Click here to Skip to main content
15,886,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm hoping after a month of trying to resolve this with no success, this site will be my saviour?

I have an aspx page running on the asp.net development server built in to visual web dev 2010.

I keep getting "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required"

This always happens on this line: SMTPServer.Send(myMessage)

my web.config: (the password is correct, I have just hidden it here for obvious reasons)

XML
<system.net>
        <mailSettings>
            <smtp>
                <network defaultCredentials ="false" host="smtp.gmail.com" port="587" userName="[DELETED]@gmail.com" password="********" />
            </smtp>
        </mailSettings>
    </system.net>



code behind:

VB
'create an SMTP client object
        Dim SMTPServer As New System.Net.Mail.SmtpClient(host)
        'configuration for the Google mail server
        SMTPServer.Host = host
        SMTPServer.Port = port
        SMTPServer.EnableSsl = True
        SMTPServer.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
        SMTPServer.UseDefaultCredentials = defaultCredentials
        SMTPServer.Credentials = New System.Net.NetworkCredential("username", "password")
Posted
Updated 2-Jan-11 0:30am
v3
Comments
#realJSOP 2-Jan-11 6:22am    
When you have code snippets surrounded by <pre> tags, make sure you uncheck the "Ignore HTML" box when entering your question.
OriginalGriff 2-Jan-11 6:31am    
...And don't post your email to any public forum, unless you really like spam!

1 solution

I tried this and it worked :

Dim Email As New System.Net.Mail.MailMessage("myMail@gmail.com", "otherMail@hccnet.nl")
Email.Subject = "test subject"
Email.Body = "this is a test"
Dim mailClient As New System.Net.Mail.SmtpClient()
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("myUsername", "myPassword")
mailClient.Host = "smtp.gmail.com"
mailClient.Port = 587
mailClient.EnableSsl = True
mailClient.UseDefaultCredentials = False
mailClient.Credentials = basicAuthenticationInfo
mailClient.Send(Email)


Your Line
SMTPServer.Credentials = New System.Net.NetworkCredential("username", "password")

Shouldn't "username" and "password" just be username and password?

Cheers
 
Share this answer
 
Comments
Manfred Rudolf Bihy 2-Jan-11 9:33am    
I can't see where he's reading the mailsettings but going by the config file content wouldn't it be "userName"?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900