locked
SmtpClient.Send gets SmtpException "5.5.1 Authentication Required" error

    Question

  •  

    I am trying to send mail to Gmail in VSTS 2008 RTM using the code below. I am getting an SMTPException: "SMTP connection rquires a secure connection or client was not authenticated. 5.5.1 Authentication Required."

     

    What do I need to do to athenticate this email appropriately so that it will send through GMail?

     

    Gmail says tha they need the following for IMAP

     

    Incoming Mail (IMAP) Server - requires SSL: imap.gmail.com
    Use SSL: Yes
    Port: 993
    Outgoing Mail (SMTP) Server - requires TLS: smtp.gmail.com (use authentication)
    Use Authentication: Yes
    Use STARTTLS: Yes (some clients call this SSL)
    Port: 465 or 587
    Account Name: your Gmail username (including @gmail.com)
    Email Address: your full Gmail email address (username@gmail.com)
    Password: your Gmail password

     

    My Code:

     

    Using message As _

    New MailMessage(fromAddress, toAddress, subject, body)

    Dim mailClient As New SmtpClient("smtp.gmail.com", 587)

    mailClient.DeliveryMethod = SmtpDeliveryMethod.Network

    Dim mailAuthentication As System.Net.NetworkCredential

    mailAuthentication = New System.Net.NetworkCredential _

    ("myUsername@gmail.com", "ValidPassword", "smtp.gmail.com")

    mailClient.Credentials = mailAuthentication

    mailClient.EnableSsl = True

    mailClient.UseDefaultCredentials = False

    mailClient.Send(message)

    End Using

     

     

    Thanks for any assistance.

    Saturday, February 09, 2008 3:39 PM

All replies

  • Using message As _

    New MailMessage(fromAddress, toAddress, subject, body)

    Dim mailClient As New SmtpClient("smtp.gmail.com", 587)

    mailClient.DeliveryMethod = SmtpDeliveryMethod.Network

    Dim mailAuthentication As System.Net.NetworkCredential

    mailAuthentication = New System.Net.NetworkCredential _

    ("myUsername@gmail.com", "ValidPassword") //loose the domain part

    mailClient.Credentials = mailAuthentication

    mailClient.EnableSsl = True

    mailClient.UseDefaultCredentials = False

    mailClient.Send(message)

    End Using

    Thursday, April 17, 2008 12:42 PM
  • Hi Don,

    I think you should be able to find your solution here:

    http://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c-sharp

    I am not sure which of the many reasons gave you this error as its a common error message for issues in smtp server not able to get through gmail authentication.

    In my case it was the 2-step verification process of Gmail.

    Thanks,

    Yoosaf

    Sunday, September 30, 2012 9:10 PM