Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send a gmail email in vb.net?

I want to send an email, but it gives me an error.

I have this code:

Sub sendMail(ByVal title As String, ByVal content As String)
    Dim SmtpServer As New SmtpClient("smtp.gmail.com", 25)
    SmtpServer.Credentials = New Net.NetworkCredential("[email protected]", "password")
    Dim mail As New MailMessage("[email protected]", "[email protected]", title, content)
    SmtpServer.Send(mail)
End Sub

I have a try catch which tries to call this method, it doesnt work so the catch runs and i get thes exception: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. b6sm3176487lae.0 - gsmtp Why do I get this error? and how do I fix it?

like image 656
Arbitur Avatar asked Aug 09 '13 18:08

Arbitur


People also ask

How do I use Telnet with Gmail?

Type "'Telnet smtp.gmail.com 465" into the terminal window or type "Telnet smtp.gmail.com 587" if you're using Microsoft Outlook, and press "Enter."


2 Answers

Gmail uses SMTP over SSL on port 465.

Try doing:


  Dim SmtpServer As New SmtpClient("smtp.gmail.com", 465)
  ...
  SmtpServer.EnableSsl = True
  ...
like image 129
pspet Avatar answered Oct 09 '22 19:10

pspet


Try this - I know it works.

    Dim Mail As New MailMessage
    Dim SMTP As New SmtpClient("smtp.gmail.com")

    Mail.Subject = "Security Update"
    Mail.From = New MailAddress("[email protected]")
    SMTP.Credentials = New System.Net.NetworkCredential("[email protected]", "password") '<-- Password Here

    Mail.To.Add(address & "@gmail.com") 'I used ByVal here for address

    Mail.Body = "" 'Message Here

    SMTP.EnableSsl = True
    SMTP.Port = "587"
    SMTP.Send(Mail)
like image 43
nick Avatar answered Oct 09 '22 19:10

nick