C# .NET - SMTP Authenticated problem

Asked By A_S M on 09-Jan-10 05:35 AM

it's urgent please

error getting when send email- "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required"

thanks all advance

re -SMTP Authenticated problem

DL M replied to A_S M on 09-Jan-10 05:40 AM
if you are behind proxy Server then you need to write below mentioned code in your web.config file

<system.net>
<defaultProxy>
<proxy proxyaddress="YourProxyIpAddress"/>
</defaultProxy>
</system.net>



If you are still having problems them try changing port number to 587
smtp.Host = "smtp.gmail.com,587";


If you still having problems then try changing code as mentioned below

SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = False;
smtp.Credentials = new System.Net.NetworkCredential
("YourUserName@gmail.com","YourGmailPassword");
smtp.EnableSsl = true;
smtp.Send(mail);


at last check your password is it correct ??

Re

Huggy Bear replied to A_S M on 09-Jan-10 05:43 AM
The SMTP server which you are trying to use requires authentication in order to relay emails sent by your application. In other words you need to pass a valid SMTP user id and password as shown below while sending emails as shown below

SmtpClient smtpClient = new SmtpClient("smtpservername");
//Provide the username and password as shown
smtpClient.Credentials = New System.Net.NetworkCredential("username", "password");
smtpClient.Send(mailMessage);

Note: If you don't provide any user credentials to the SMTPClient then your application will do the request anonymously. So it is no surprise the Smtp server will reject the request.

re

Web Star replied to A_S M on 09-Jan-10 10:21 AM

The real work is done by the NetworkCredential object.  According to MSDN, this object "provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication."  The benefit of making this a two-step process rather than passing username and password to the .Credentials property of the SmtpClient object is not clear, but that is what is required.

Here is a fully working quick code sample that you can use to get started on your own SMTP-Auth supporting e-mail code.

'Create a new MailMessage object and specify the"From" and "To" addresses
Dim Email As New System.Net.Mail.MailMessage( _
   "Brad.Kingsley@orcsweb.com", "Brad@KingsleyTeam.com")
Email.Subject = "test subject"
Email.Body = "this is a test"
Dim mailClient As New System.Net.Mail.SmtpClient()
'This object stores the authentication values
Dim basicAuthenticationInfo As _
   New System.Net.NetworkCredential("username", "password")
'Put your own, or your ISPs, mail server name onthis next line
mailClient.Host = "Mail.RemoteMailServer.com"
mailClient.UseDefaultCredentials = False
mailClient.Credentials = basicAuthenticationInfo
mailClient.Send(Email)