Click here to Skip to main content
11,719,185 members (87,968 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: IIS7 C#
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
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

<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 3-Sep-12 18:58pm
Edited 3-Sep-12 19:14pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.[^]
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 1,734
1 OriginalGriff 690
2 Maciej Los 569
3 Richard MacCutchan 540
4 F-ES Sitecore 510


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 4 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100