Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting following error while sending a mail from my website. In local iis it is working but in production server it is getting following error.

Sys.WebForms.PageRequestManagerServerErrorException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

The code i have written is
C#
public void SendMail(string ToEmailAddress, string Body, string Subject)
        {
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Host = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"].ToString();
            smtpClient.Port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientport"].ToString());
            smtpClient.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["FromEmail"].ToString(), System.Configuration.ConfigurationManager.AppSettings["MailPassword"].ToString());
            smtpClient.EnableSsl = true;
            MailMessage messege = new MailMessage();
            MailAddress mailAddress = new MailAddress(System.Configuration.ConfigurationManager.AppSettings["FromEmail"].ToString(), System.Configuration.ConfigurationManager.AppSettings["Name"].ToString());
            messege.From = mailAddress;
            messege.To.Add(ToEmailAddress);
            messege.Subject = Subject;
            messege.Body = Body;
            messege.IsBodyHtml = true;
            smtpClient.Send(messege);
        }      


In web.config i have mention settings like

XML
<appSettings>
       <add key="SmtpClientHost" value="smtp.gmail.com"/>
       <add key="SmtpClientport" value="587"/>
       <add key="FromEmail" value="crackersstore@gmail.com"/>
       <add key="MailPassword" value="myPassword"/>
       <add key="Name" value="CRACKERSADMIN"/>
   </appSettings>

Please help me
Posted
Updated 3-Sep-12 19:14pm
v3

1 solution

Try configuration like following, 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[^]


Have a look at this tip too: Sending an Email in C# with or without attachments: generic routine.[^]
 
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