Mark Tabor

Mark Tabor

  • 570
  • 1.9k
  • 429.7k

Email send using asp.net vb.net

Jul 22 2016 6:01 AM
I am trying to send an email from gmail account to another domain account which i have purchased , i have two methods one methods is working fine but the other is not giving any exception and not sending any email check these two methods the first one works fine 
1-
Private Sub SendEmail()
GetUserIDEmail(Session("LoggedInUserId"))
Dim Mail As New MailMessage
Try
Mail.IsBodyHtml = True
Dim MailText As String = Nothing
'Dim attachment As System.Net.Mail.Attachment
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' font-size:14px;Color='#000000'><b><br/>" + AcceptComments & """</font> " + Environment.NewLine
MailText = MailText + "<font Face='Verdana' font-size:14px;Color='#000000'><b><br/>" & " Regards," & " " & "<br/>" & "<i>Plan Pakistan RBME TEAM<i>" + "</b></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("[email protected]")
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("[email protected]", "forgot123")
SMTP.Port = 587
SMTP.Send(Mail)
Catch ex As Exception
ex.Message.ToString()
End Try
End Sub
-----------------------------------------------------------------------
2-This one is not working what is the reason
Private Sub SendHtmlFormattedEmail(ByVal recepientEmail As String, ByVal subject As String, ByVal body As String)
Dim Mail As New MailMessage
Mail.From = New MailAddress("[email protected]")
Mail.Subject = subject
Mail.Body = body
Mail.IsBodyHtml = True
Mail.To.Add("[email protected]")
Mail.From = New MailAddress("[email protected]")
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("[email protected]", "forgot123")
SMTP.Port = 587
SMTP.Send(Mail)
End Sub
 this second method works fine for gmail but not for my domain email address which i have purchased 
 

Answers (18)