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("[email protected]")
mailMessage.Bcc.Add("[email protected]")
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("[email protected]")
Dim smtp As New SmtpClient()
smtp.Host = "202.165.228.15"
smtp.EnableSsl = False
smtp.Credentials = New System.Net.NetworkCredential("[email protected]", "Pakistan_123")
smtp.Port = 25
smtp.Send(mailMessage)
Catch ex As Exception
ex.Message.ToString()
End Try
End Sub
My mailMessage.To.Add(New MailAddress(recepientEmail)) this line get an email like [email protected] when i send email nothing comes to [email protected] , but when i hard code this email address in mailMessage.TO.ADD([email protected]) it works , secondly i want to tell you that when i show the value of this line in watch window it shows correct address {mailMessage.To.Add(New MailAddress(recepientEmail))} , secondly when this method comes up with gmail or yahoo mail email address then it also works fine , it just did not work with [email protected]. why it is so
Raja TRank #685 · 3.5K reputationPosted Jul 31, 2016, 12:55 PM EDT
Praveen SreeramRank #134 · 16.8K reputationPosted Jul 31, 2016, 6:05 PM EDT
Mark TaborRank #914 · 2.3K reputationPosted Jul 31, 2016, 8:29 PM EDT
Mark TaborRank #914 · 2.3K reputationPosted Jul 31, 2016, 9:05 PM EDT
mailMessage.To.Add("[email protected]") then it send email correctly , secondly for gmail and yahoo mail it did not have any problem either i have to bind the TO address from database or hard code it , what would be the issue {-} is the issue in the email does - is not allowed in email addresses
Rajeev PunhaniRank #551 · 4.4K reputationPosted Aug 1, 2016, 1:53 AM EDT
Hi Mark,
I think the email address you are passing to the function contains some extra spaces ,so try trimming it.
If the above solution is helpful then,accept the answer.
Mark TaborRank #914 · 2.3K reputationPosted Aug 1, 2016, 2:53 AM EDT
Rajeev PunhaniI have tried that too
Mark TaborRank #914 · 2.3K reputationPosted Aug 1, 2016, 11:22 PM EDT
Raja T,
Praveen Kumar Sreeram
Rajeev Punhani
Rajeev Punhani
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts