Reputation: 5961
i am developing with vb2005, using system.net.mail to send mail using google configuration. a full sample of my code was posted here earlier
With smtp
.Host = "smtp.google.com"
.Port = 465
.UseDefaultCredentials = False
.Credentials = New System.Net.NetworkCredential(mygoogleemail, mypass)
.EnableSsl = true
.Timeout = 60000
End With
i get the operation has timed out. if i change the port to 587, it says that the server does not support secure connection
[EDIT] could firewall be blocking it?
is there anyway to specify sending application name?
Upvotes: 0
Views: 7123
Reputation: 1
If you are using TWO STEP VERIFICATION for gmail, then disable it first and then try again with this code
Dim myLogin As New NetworkCredential("[email protected]", "password")
Dim msg As New MailMessage("[email protected]", "[email protected]", "subjectLine", "emailBodyText")
msg.IsBodyHtml = True
Try
Dim client As New SmtpClient("smtp.gmail.com", 587)
client.EnableSsl = True
client.UseDefaultCredentials = false
client.Credentials = myLogin
client.Send(msg)
Catch ex As SmtpException
msgbox(ex.Message)
End Try
Upvotes: 0
Reputation: 18792
Try
Dim myLogin As New NetworkCredential("[email protected]", "password")
Dim msg As New MailMessage("[email protected]", "[email protected]", "subjectLine", "emailBodyText")
msg.IsBodyHtml = True
Try
Dim client As New SmtpClient("smtp.gmail.com", 587)
client.EnableSsl = True
client.UseDefaultCredentials = false
client.Credentials = myLogin
client.Send(msg)
Catch ex As SmtpException
msgbox(ex.Message)
End Try
If you get the timeout then troubleshoot
Try to TELNET the mail server to see if you are able to send relay mails via your ISP
Open command prompt and type (without quotes) telnet smtp.gmail.com 25
If you get a timeout then the problem is either your local LAN is blocking mails or your ISP.
Upvotes: 2
Reputation: 11773
The port was right in the OP, but the host was wrong
With smtp
.Port = 465 '465 for ssl
.EnableSsl = True
.UseDefaultCredentials = False
.Credentials = New System.Net.NetworkCredential("[email protected]", "yourpassword")
.Host = "smtp.gmail.com"
End With
And just to verify, you have pop enabled in gmail, correct?
Upvotes: 1
Reputation: 4422
Have you tried the answer at : Sending email through Gmail SMTP server with C#
Just to see if that works.
Note that in the answer to his solution he mentions web.config changes lower in the post not accepted as the answer
<system.net>
<mailSettings>
<smtp from="[email protected]" deliveryMethod="Network">
<network defaultCredentials="false" enableSsl="true" host="smtp.gmail.com" port="587" password="password" userName="[email protected]"/>
</smtp>
</mailSettings>
</system.net>
Upvotes: 2
Reputation: 55200
The Port number is 587.
And also, try this order as per this solution
With smtp
.UseDefaultCredentials = False
.Credentials = New System.Net.NetworkCredential("[email protected]", "mypwd")
.Host = "smtp.gmail.com"
.Port = 587
.EnableSsl = true
End With
Upvotes: -1