Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

VB
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:
VB
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"><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
Posted
v2
Comments
F-ES Sitecore 25-Jul-16 7:01am    
If the message body is different then it's probably getting flagged as spam.

Don't use gmail to send email though, especially anything business critical, use the smtp server provided by your web host, or system admin if it's internal hosting.
Yes, most likely.
Malikdanish 25-Jul-16 7:22am    
I want to send an email to a company domain account like danish.habib@plan-international.org
Is it going to spam? Have you checked?
Malikdanish 25-Jul-16 7:41am    
I have outlook configured it has inbox,Drats,SentItem,deletedItems,Junk,outbox,Clutter, No Spam folder and in these my email does not coming in these folder

1 solution

After so much of discussion, seems like you are missing something.

Please refer my past answer, which gives the whole code to send mail using gmail. sending email to gmail from asp.net[^]
 
Share this answer
 
Comments
Malikdanish 27-Jul-16 3:14am    
thanks for assistance my code works fine for other email addresses except my company domain email address danish.habib@plan-international.org
, I have another method which is sending email correctly to all email address but that method is not formatting the email content so i wrote another method which is not sending email .
What is the exception?
Malikdanish 28-Jul-16 3:53am    
no exception I have two method to send an email the one having the formatting does not send an email and the other one send correctly , they both are good with other email accounts excepts my domain email like danish.h@plan-international.org the second method have no formatting works on all email address but the first one having formatting does not work on that domain and work on other domains . today i got an email from the method which does not sending email i got email like below
Now i have received an email which says
Here is your quarantine summary for 7/27/2016 - 7/28/2016:

These messages were quarantined before they reached your inbox as potential spam. The quarantined messages can be sent to your inbox using the Deliver links below. This will train the system not to identify similar messages as spam.
system not to identify similar messages as spam.

Subject

Sender

Date

Action

Record Accepted

rbme@planrbme.com.pk

7/28/2016 6:59 AM

Deliver

Record Accepted

rbme@planrbme.com.pk

7/28/2016 6:44 AM

Deliver

it means they are considering it as spam and then send an email to me here i have to click the Deliver Action then it get send ? what is the work around to fix this issue ?
Contact your system admin who manages the email server. He should allow the html content.
Malikdanish 1-Aug-16 1:11am    
When i am getting my domain email address by calling a method then it does not send email to that address when i hard coded it then it send the email my domain email is d.habib@plan-international.org , below the code of send email 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.CC.Add("danish.habib@plan-international.org")

mailMessage.Bcc.Add("spober_woh@yahoo.com")

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

mailMessage.From = New MailAddress("omer@planrbme.com.pk")


Dim smtp As New SmtpClient()

smtp.Host = "202.165.228.15"

smtp.EnableSsl = False

smtp.Credentials = New System.Net.NetworkCredential("omer@planrbme.com.pk", "Pakistan_123")

smtp.Port = 25

smtp.Send(mailMessage)


Catch ex As Exception

ex.Message.ToString()

End Try

End Sub

End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900