I use this code for smtp mail in vb.net

Posted by Sekar.C under VB.NET on 3/16/2012 | Points: 10 | Views : 4033 | Status : [Member] | Replies : 4
hi,

I use this code for smtp mail in vb.net
try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New Net.NetworkCredential("username@gmail.com", "password")
SmtpServer.Port = 25
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
mail = New MailMessage()
mail.From = New MailAddress("asokmailworld@gmail.com")
mail.To.Add("sekar.mca2009@gmail.com")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail sent")
Catch ex As Exception
MsgBox(ex.Message)
End Try

I got this error how to solve this error
To attempt fixing network connectivity problems, click Tools, and then click "Diagnose Connection Problems..."

Regards
Sekar.c



Responses

Posted by: Sksamantaray on: 3/16/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Sekar,
Try this.
I have tested it.I think you have received test mail as well.

Try

Dim SmtpServer As New SmtpClient()

Dim mail As New MailMessage()

SmtpServer.Port = 25

SmtpServer.Host = "127.0.0.1"

'SmtpServer.EnableSsl = True

mail = New MailMessage()

mail.From = New MailAddress("sanjayasamantaray@gmail.com")

mail.To.Add("sekar.mca2009@gmail.com")

mail.Subject = "Test Mail"

mail.Body = "Testing your code......"

SmtpServer.Send(mail)

MsgBox("mail sent")

Catch ex As Exception

MsgBox(ex.Message)

End Try


Thanks,
Sanjay

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/16/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Sekar,
Let me know it works for you and Mark As answer.

Thanks,
Sanjay

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/16/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi sekar,

just change SMTPServer.Port value from 25 to 587,
and if its work then Mark this as answer...............

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/17/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi sekhar,

Try out this:

try

Dim SmtpServer As New SmtpClient()

Dim mail As New MailMessage()

SmtpServer.Credentials = New Net.NetworkCredential("username@gmail.com", "password")

SmtpServer.Port = 587

SmtpServer.Host = "smtp.gmail.com"
dim basicCredential = new System.Net.NetworkCredential("asokmailworld@gmail.com", "**************")

SmtpServer.UseDefaultCredentials = true
SmtpServer.Credentials = basicCredential

SmtpServer.EnableSsl = True

mail = New MailMessage()

mail.From = New MailAddress("asokmailworld@gmail.com")

mail.To.Add("sekar.mca2009@gmail.com")

mail.Subject = "Test Mail"

mail.Body = "This is for testing SMTP mail from GMAIL"

SmtpServer.Send(mail)

MsgBox("mail sent")

Catch ex As Exception

MsgBox(ex.Message)

End Try


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response