Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,
I am facing a problem.
When I run the code to send email on my machine it works well. It sends mail in HTML Format, but when I put the exe on server it didn't sends in HTML format.
In the mail I get all the HTML tags.

I did the code is:
C#
MailMessage message = new MailMessage();
            SmtpClient client = new SmtpClient();
            try
            {
                message.From = new MailAddress(fromemail, fromname);
                message.Subject = subject;
                //message.Body = body;
                //message.IsBodyHtml = true;
                message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(body, null, "text/html")); 
                message.To.Add(new MailAddress(to));
                if (cc != "")
                {
                    foreach (string str in cc.Split(new char[] { ',' }))
                    {
                        message.CC.Add(new MailAddress(str.Trim()));
                    }
                }
                if (bcc != "")
                {
                    foreach (string str2 in bcc.Split(new char[] { ',' }))
                    {
                        message.Bcc.Add(new MailAddress(str2.Trim()));
                    }
                }
                client.Host = server;
                client.EnableSsl = true;
                NetworkCredential credential = new NetworkCredential
                {
                    UserName = new MailAddress(fromemail, fromname).Address,
                    Password = frompwd
                };
                client.UseDefaultCredentials = true;
                client.Credentials = credential;
                client.Port = 0x24b;
                client.Send(message);
Posted
Updated 3-May-13 23:39pm
v3

That could be because you have commented out the line:
C#
//message.IsBodyHtml = true;
Since this defaults to false, the HTML elements will be ignored when they are received. Try uncommenting it, and re-compile both debug and release versions.
 
Share this answer
 
Griff,
I have tried with this .

//message.IsBodyHtml = true;--------2
message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(body, null, "text/html"));------------3

I used line 2 & 3 one by one to get html format but still not getting the result
 
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