1

I have the following code for generating an HTML e-mail:

reader = cmd.ExecuteReader();
while (reader.Read())
{

     mailbody +=
        "<tr>" +
        "<td>" + reader["DevName"].ToString() + "</td>" +
        "<td>" + reader["DevId"].ToString() + "</td>" +
        "<td>" + reader["LocationID"].ToString() + "</td>" +
        //"<td>" + reader["LocationName"].ToString() + "</td>" +
        "<td>" + reader["SubLocationID"].ToString() + "</td>" +
        "<td>" + reader["IPV6"].ToString() + "</td>" +
        "<td>" + reader["LastConnTime"].ToString() + "</td>" +
        "<td>" + reader["LastDisconnTime"].ToString() + "</td>" +
        "<td>" + reader["Online"].ToString() + "</td>" +
        "<td>" + reader["HardwareSerialNumber"].ToString() + "</td>" +
        "<td>" + reader["ServiceProviderID"].ToString() + "</td>" +
        "<td>" + reader["DateLastModified"].ToString() + "</td>" +
        "<tr>";
}

if (mailbody !=string.Empty)
{
    mailbody += "</table>";
    string bodyStructure = "<html><head></head><body>" + @"<table border =""1"" cellpadding=""2"" style=""border=collapse:collapse;""><tr style=""color:white; background-color:SkyBlue; font-wieght:bold;"">" + "<td>DeviceName</td> <td>DeviceID</td>  <td>LocationID</td> <td>LocationName</td>   <td>SubLocationID</td>  <td>IPAddress</td>  <td>LastConnected</td>  <td>LastDisconnected</td> <td>HardwareSerialNumber</td>  <td>DeviceStatus</td> <td>HardwareSerialNumber</td>  <td>ServiceProviderID</td>  <td>LastTransactionSync</td>" + "</tr>" + mailbody + "</body</html>";
    message.IsBodyHtml = true;
    message.Subject = "DeleteDuplicateDevicesReport";
    message.Body = bodyStructure;
    smtp.Send(message);
}

Here the reader will generate each row, of the table, and then be merged into the rest of my HTML template.

This is the e-mail as I receive it: enter image description here

Why does my e-mail arrive without the HTML being rendered?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
NAGARAJA H I
  • 149
  • 3
  • 11
  • 1
    It seems you can skip the ``, `, and `` tags, as the `message.IsBodyHtml` already declares that you are sending body HTML: https://stackoverflow.com/questions/8628683/how-to-send-html-formatted-email. Also, for what it's worth, the code you provided does not properly format the closing body tag (` – tshimkus Feb 05 '19 at 05:50
  • This looks basically the same as we're using for sending HTML e-mail. The only difference is that we set the body _after_ we set `IsBodyHtml`, but I don't imagine that would make a difference. – ProgrammingLlama Feb 05 '19 at 05:54

0 Answers0