0

in my wpf application i need to send an email and the body of the list i need to send a list of items.Now everything works fine except that the body is not rendred to the format that i wrote in my code. This is the function that send an email:

public static void CreateTimeoutTestMessage(string ParentAdress, List<KidHistory> list,Parent p,Enfant e)
    {

        var fromAddress = new MailAddress("famissima.mic@gmail.com", "famissima.mic");
        var toAddress = new MailAddress(ParentAdress);
        const string fromPassword = "xxxxxxxxxx";
        const string subject = "Subject";
        var smtp = new SmtpClient
        {
            Host = "smtp.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Timeout = 20000,
            Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
        };
        var message = new MailMessage(fromAddress, toAddress);
        message.Subject = subject;
        if (p.Civilite == "Mr")
            message.Body += "Bonjour Mr. " + " " + p.Nom + " " + p.Prenom + " ,l'historique de navigation de votre enfant " + e.pseudo + " est: ";
        else
            message.Body += "Bonjour M. " + " " + p.Nom + " " + p.Prenom + " ,l'historique de navigation de votre enfant " + e.pseudo + " est: ";
        message.Body += "<table width='100%' style='border:Solid 1px Black;'>";
        foreach (var item in list)
        {
            message.Body += "<tr>";
            message.Body += "<td stlye='color:blue;'>" + item.url + "</td>" + "<td stlye='color:blue;'>" + item.StartDate + "</td>" + "<td stlye='color:blue;'>" + item.FinishDate + "</td>";
            message.Body += "</tr>";
        }
        message.Body += "</table>";
        smtp.Send(message);
    }

and this is the output(the received mail): the result

Rami Raddaoui
  • 75
  • 1
  • 5
  • 13
  • possible duplicate of [Send a email with a HTML file as body (C#)](http://stackoverflow.com/questions/1155797/send-a-email-with-a-html-file-as-body-c) – nemesv Apr 13 '14 at 12:30

1 Answers1

1

Setting IsBodyHtml to true allows you to use HTML tags in the message body:

message.IsBodyHtml = true;
Seany84
  • 5,526
  • 5
  • 42
  • 67
  • @RamiRaddaoui Glad it worked for you. Can you accept my answer please. See here for further information: http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235 – Seany84 Apr 13 '14 at 12:37