HalCHub
asked on
system.net.mail requires starttls
how to I fix I get an error that it requires a starttls
Imports System.Net.Mail
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New Net.NetworkCredential("me@ gmail.com" , "password")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("me@gmail.com" , "my name")
mail.To.Add("me@hotmail.co m")
mail.Subject = "Test Mail"
mail.Body = "This Is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Imports System.Net.Mail
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New Net.NetworkCredential("me@
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("me@gmail.com"
mail.To.Add("me@hotmail.co
mail.Subject = "Test Mail"
mail.Body = "This Is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
ASKER
nope here is a different version
Private Sub test(Optional ByVal smtp As String = "smtp.gmail.com")
Dim toAdd As String = " test@gmail.com"
Dim fromAdd As String = "test@gmail.com"
Dim pass As String = "pswd"
Dim client As SmtpClient = New SmtpClient(smtp)
Dim mail As New MailMessage
mail.From = New MailAddress(fromAdd)
mail.To.Add(toAdd)
mail.Subject = "Test Zip File"
mail.Body = "This Is just a test"
client.Port = 465 '465 587 25
client.Credentials = New System.Net.NetworkCredenti al(fromAdd , pass)
client.EnableSsl = True
MsgBox("here")
' client.Timeout = Int32.MaxValue
Try
client.Send(mail)
Catch ex As SmtpException
MsgBox(ex.Message)
End Try
MsgBox("done")
End Sub
port 465 times out
port 25 gives a starttls error
port 587 give required secure connection
Private Sub test(Optional ByVal smtp As String = "smtp.gmail.com")
Dim toAdd As String = " test@gmail.com"
Dim fromAdd As String = "test@gmail.com"
Dim pass As String = "pswd"
Dim client As SmtpClient = New SmtpClient(smtp)
Dim mail As New MailMessage
mail.From = New MailAddress(fromAdd)
mail.To.Add(toAdd)
mail.Subject = "Test Zip File"
mail.Body = "This Is just a test"
client.Port = 465 '465 587 25
client.Credentials = New System.Net.NetworkCredenti
client.EnableSsl = True
MsgBox("here")
' client.Timeout = Int32.MaxValue
Try
client.Send(mail)
Catch ex As SmtpException
MsgBox(ex.Message)
End Try
MsgBox("done")
End Sub
port 465 times out
port 25 gives a starttls error
port 587 give required secure connection
Your code looks fine, assuming you are using a valid email/user/pass in your actual code.
This google support article has more ideas for testing
https://support.google.com/mail/answer/78775?hl=en
The first is to confirm that you can log into the account you are using manually and so validate your credentials
Another good test is telnet to confirm that a connection can be made from your machine
eg telnet smtp.gmail.com 587
This google support article has more ideas for testing
https://support.google.com/mail/answer/78775?hl=en
The first is to confirm that you can log into the account you are using manually and so validate your credentials
Another good test is telnet to confirm that a connection can be made from your machine
eg telnet smtp.gmail.com 587
<network host="smtp.gmail.com" enableSsl="true" ... />
kind the like us if its works for u
http://weblogs.asp.net/scottgu/tip-trick-enabling-ssl-on-iis7-using-self-signed-certificates
http://weblogs.asp.net/scottgu/tip-trick-enabling-ssl-on-iis7-using-self-signed-certificates
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Open in new window
https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl.aspx