I have two methods the first one is the simplest one like below , while in second one i am formatting my email content , the second method calls another method to format and then it calls another method for smtp settings, the first method works fine it is sending email to my domain email address like omer@planrbme.com.pk while the second method is not sending email to my domain emil address omer@planrbme.com.pk , it is sending email to all others but not to my domain email address . below are the two methods the first one is fine but the second one is sending email to all other email address except my domain email address why it is so.
First Method:
Private Sub SendHtmlFormattedEmail(ByVal recepientEmail As String, ByVal subject As String, ByVal body As String)
Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage
Try
mailMessage.From = New MailAddress(ConfigurationManager.AppSettings("UserName"))
mailMessage.Subject = subject
mailMessage.Body = body
mailMessage.IsBodyHtml = True
mailMessage.To.Add(New MailAddress(recepientEmail))
Dim files As List(Of HttpPostedFile) = DirectCast(Cache(Me.Key), List(Of HttpPostedFile))
For Each file As HttpPostedFile In files
mailMessage.Attachments.Add(New Attachment(file.InputStream, Path.GetFileName(file.FileName), file.ContentType))
Next
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("sweet.uet@gmail.com", "forgot123")
SMTP.Port = 587
SMTP.Send(mailMessage)
smtp.Send(mailMessage)
Catch ex As Exception
ex.Message.ToString()
End Try
End Sub
Second Method:
Private Sub SendEmail()
GetUserIDEmail(Session("LoggedInUserId"))
Dim Mail As New MailMessage
Try
Mail.IsBodyHtml = True
Dim MailText As String = Nothing
Mail.Subject = " Report Submitted By : " & Session("LoggedInUserFullName") & " " & "User Type :" & GetUserTypeName(CInt(Session("UserTypes")))
MailText = MailText + "<font face="verdana" color="#000000">" & "Dear User, " & "</font><br /><br />" & Environment.NewLine
MailText = MailText + "<font face="verdana" color="#000000">" + " " & "we are glad to inform you that your records has accepted.</font>" & "<br /> ""<font face="Verdana"><br />" + AcceptComments & """</font> " + Environment.NewLine
MailText = MailText + "<font face="Verdana"><br />" & " Regards," & " " & "<br />" & "Plan Pakistan RBME TEAM" + "</font>" & vbCrLf
Mail.IsBodyHtml = True
Mail.Body = MailText
Dim files As List(Of HttpPostedFile) = DirectCast(Cache(Me.Key), List(Of HttpPostedFile))
For Each file As HttpPostedFile In files
Mail.Attachments.Add(New Attachment(file.InputStream, Path.GetFileName(file.FileName), file.ContentType))
Next
Mail.From = New MailAddress("sweet.uet@gmail.com")
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("sweet.uet@gmail.com", "forgot123")
SMTP.Port = 587
SMTP.Send(Mail)
Catch ex As Exception
ex.Message.ToString()
End Try
End Sub
What I have tried:
have tried that too
ServicePointManager.ServerCertificateValidationCallback = AddressOf OnValidateCertificate
ServicePointManager.Expect100Continue = True