Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

I am having an send email functionality in c# application.
Following is the code I am using to send email -

C#
public static bool SendMail(string toList, string from, string ccList, string subject, string body)
       {
           bool flag = false;
           MailMessage message = new MailMessage();
           SmtpClient smtpClient = new SmtpClient();
           string msg = string.Empty;
           try
           {
               MailAddress fromAddress = new MailAddress(from);
               message.From = fromAddress;
               message.To.Add(toList);
               if (ccList != null && ccList != string.Empty)
                   message.CC.Add(ccList);
               message.Subject = subject;
               message.IsBodyHtml = true;
               message.Body = body;

               smtpClient.Host = "smtp.compName.org";
               smtpClient.Port = 587;
               smtpClient.EnableSsl = false;
               smtpClient.UseDefaultCredentials = true;
               smtpClient.Credentials = new System.Net.NetworkCredential(UserName,Password);
               smtpClient.Send(message);
               flag = true;

           }
           catch (Exception ex)
           {
               msg = ex.Message;

           }
           return flag;
       }


I am using the same function from more than 8 months. Suddenly what happens I didn't understand.

I am not getting any emails from my applications. It has log entries - Mail sent successfully.
There is no any exception.


From above code I have commented message.IsBodyHtml = true; this line and I am getting emails but its html code.

What is the problem I am not understanding!!!
I am using network solutions service to send email.

Please suggest , ASAP.

Thanks for your suggestions in advance.

Regards,
Avinash
Posted
Updated 20-Mar-13 23:36pm
v2
Comments
Prasad Khandekar 21-Mar-13 5:57am    
As per documentation You need to set IsBodyHtml to true if you want to send HTML emails. If you are sending plain text emails then you will not require it. In your case since your code was working initially it might be relate to your mail server setting. Please contact the mail server administrator and see if HTML mail option is blocked.
Avinash6474 21-Mar-13 6:01am    
Thank you Prasad , I will confirm with the service provider.

1 solution

The problem with the service provider which I am using, after talking with them came to know that the web mail server was down , no problem with send mail functionality.
 
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