Reputation: 11
i made an application where i need to send some of information to my self i am clueless what to do so i decided it to send through email which also not working giving timeout error here is the code
`Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim s As New SmtpClient
s.Host = "smtp.gmail.com"
s.Port = 465
s.EnableSsl = True
s.Timeout = 55000
s.UseDefaultCredentials = False
s.Credentials = New NetworkCredential("********@gmail.com", "*************")
Dim m As New MailMessage
m.To.Add("******@gmail.com")
m.From = New MailAddress("*******@gmail.com")
m.Body = "Test Message"
m.Subject = "Test Subject"
s.Send(m)
MsgBox("done")
Exit Sub
End sub`
Upvotes: 0
Views: 76
Reputation: 7726
We use port 587 for sending e-mails via a .NET application. Ensure that the sender's Gmail account has access to "Less secured app" permission as shown:
See if it works, if doesn't, then try the following code and don't forget to customize it with your sufficient information:
Dim SmtpCRequest As New SmtpClient
Dim MailProperty As New MailMessage()
With SmtpCRequest
.UseDefaultCredentials = False
.Credentials = New Net.NetworkCredential(<username>, <password>)
.Port = 587
.EnableSsl = True
.Host = "smtp.gmail.com"
End With
With MailProperty
.From = New MailAddress(New TripleDES("TOKEN").DecryptData(Cred(0)))
.To.Add("******@gmail.com")
.Subject = "Your Subject"
.IsBodyHtml = False
.Body = "Email Body is here."
End With
SmtpCRequest.Send(MailProperty)
MailProperty.Dispose()
Upvotes: 0