Click here to Skip to main content
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 458
1 OriginalGriff 344
2 George Jonsson 233
3 Animesh Datta 130
4 Shemeemsha RA 128
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 4 Sep 2012
Copyright © CodeProject, 1999-2014
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