Click here to Skip to main content
15,895,370 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
System.Net.Mail.SmtpClient smtpClient = new SmtpClient(strSmtpServer, int.Parse(strPort));
		smtpClient.UseDefaultCredentials = false;

		System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
		System.Net.NetworkCredential basicCredential = new System.Net.NetworkCredential();
		try
		{
			
			basicCredential.UserName = strSender;
			basicCredential.Password = strSenderPass;

			System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress(strSender, "NameToDisplay");
			message.From = fromAddress;//here you can set address
			message.To.Add(strReceiver);//here you can add multiple to
			message.Subject = strSubject;//subject of email
			//message.CC.Add("cc@site.com");//ccing the same email to other email address
			//message.Bcc.Add(new MailAddress("bcc@site.com"));//here you can add bcc address

			message.IsBodyHtml = true;	//To determine email body is html or not
			message.Body = strMessage;
			smtpClient.EnableSsl = true;
			smtpClient.Send(message);
		}

		catch (Exception ex)
		{
			return false;
		}

		return true;

I get the following Exception:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at...

Why? Is there any mistake in above method?

Help me.
Thanks.
Posted
Updated 1-Mar-11 3:03am
v3

Error suggests that it's an authentication issue. Make sure that the Firewall permissions are in place and the credentials used are correct and allowed.

Also, make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>

If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
 
Share this answer
 
hi you need to going to gmail account and confirm the Ip address your server and then try to send .
in the web config enablessl = true .
this is work............
 
Share this answer
 

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