Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dim SmtpServer As New SmtpClient("smtp.gmail.com", 465)
Dim mail As New MailMessage("***********@gmail.com", "*************@gmail", "greetings", "Hi")
SmtpServer.Credentials = New Net.NetworkCredential("***********@gmail.com", "******")
SmtpServer.Send(mail)

I am trying to use the above code but it fails to send mail. Please can anyone help me. Also, do i need to configure the smtp server? Please help me out with my code. Also, do i need to add textboxes in my vb form or should i just have a button to execute the whole program.
Posted

Check this out:
1. vb.net_send_email[^]
2. send email via vb.net[^]
 
Share this answer
 
Hi
VB
Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New Net.NetworkCredential("yourusername", "yourpassword")
            SmtpServer.Port = 587'used gamil outgoing TSL port here - enter your own
            SmtpServer.Host = "smtp.gmail.com"'used gmail as host - enter your own host
            mail = New MailMessage()
            mail.From = New MailAddress("youremailaddress")
            mail.To.Add("addresstosendto")
            mail.Subject = "Add subject here"
            mail.Body = "add body here"
            SmtpServer.Send(mail)



use port no 587 instead of 465



Regards
Aravind
 
Share this answer
 
Try this:
VB
Dim pweda As String = "FromMailPassword"
'(ConfigurationManager.AppSettings["password"]);
Dim from As String = "FromYourmail@gmail.com"
'Replace this with your own correct Gmail Address
Dim [to] As String = "abc@gef.com"
'Replace this with the Email Address to whom you want to send the mail
Dim mail As New System.Net.Mail.MailMessage()
mail.[To].Add([to])
mail.From = New MailAddress(from)
mail.Subject = "This is a test mail"
mail.SubjectEncoding = System.Text.Encoding.UTF8
mail.Body = "Test Mail."

mail.Priority = MailPriority.High
Dim client As New SmtpClient()

'Add the Creddentials- use your own email id and password
client.UseDefaultCredentials = False
client.Credentials = New System.Net.NetworkCredential(from, pweda)
client.Port = 587
' Gmail works on this port
client.Host = "smtp.gmail.com"
client.EnableSsl = True
'Gmail works on Server Secured Layer
Try
	client.Send(mail)
	Response.Write("Message Sent...")
Catch ex As Exception
	Dim ex2 As Exception = ex
	Dim errorMessage As String = String.Empty
	While ex2 IsNot Nothing
		errorMessage += ex2.ToString()
		ex2 = ex2.InnerException
	End While
	HttpContext.Current.Response.Write(errorMessage)
End Try


Thanks Tadit
 
Share this answer
 
Comments
Surajit Das 11-Mar-14 7:59am    
Thank you guys for your help. But i tried to use all of the above suggestions but still it doesnt work. So, i need to clear something. Do i need to configure the outgoing gmail TSL port because i have just written the code in vb.net and i dint change any settings anywhere. So, please can anyone suggest me what could be the problem? ThANKS

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