Private Sub sendmailwithattachment(ByVal [To] As String, ByVal subject As String, ByVal body As String, ByVal attach As FileUpload)
Try
Dim loginInfo As New NetworkCredential("-your mail id -", "-password-")
Dim msg As New System.Net.Mail.MailMessage()
msg.From = New MailAddress("-your mail id -")
msg.[To].Add(New MailAddress([To]))
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = True
Dim fileName As String = Path.GetFileName(attach.PostedFile.FileName)
Dim myAttachment As New Attachment(attach.FileContent, fileName)
msg.Attachments.Add(myAttachment)
Dim client As New SmtpClient("smtp.gmail.com")
client.EnableSsl = True
client.UseDefaultCredentials = False
client.Credentials = loginInfo
client.Send(msg)
lblMsg.Text = "mail send"
Catch ex As Exception
lblMsg.Text = "mail sending failed"
Return
End Try
End Sub
No comments:
Post a Comment