Skip to content

Instantly share code, notes, and snippets.

@munirwanis
Last active August 29, 2015 14:27
Show Gist options
  • Save munirwanis/fc5513374bffa7463244 to your computer and use it in GitHub Desktop.
Save munirwanis/fc5513374bffa7463244 to your computer and use it in GitHub Desktop.
// A variável de entrada pode ser qualquer outra coisa, ou nada, é só trocar o item abaixo
// Função para montar o body do email
public string GetMailBody(List<T> resultToMail) {
var body = new StringBuilder();
body.AppendLine("<html><head>");
body.AppendLine(@"<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>");
body.AppendLine("<meta charset='UTF-8'>");
body.AppendLine("</head><body>");
body.AppendLine("<h2>Header Text</h2>");
body.AppendLine("<table><tr>");
body.AppendLine("<th>Table Header 1</th>");
body.AppendLine("<th>Table Header 2</th>");
body.AppendLine("<th>Table Header 3</th>");
body.AppendLine("<th>Table Header 4</th>");
body.AppendLine("<th>Table Header 5</th>");
body.AppendLine("<th>Table Header 5</th>");
body.AppendLine("</tr>");
foreach (var item in resultToMail) {
body.AppendLine("<tr>");
body.AppendLine("<td>" + item.TableItem1 + "</td>");
body.AppendLine("<td>" + item.TableItem2 + "</td>");
body.AppendLine("<td>" + item.TableItem3 + "</td>");
body.AppendLine("<td>" + item.TableItem4 + "</td>");
body.AppendLine("<td>" + item.TableItem5 + "</td>");
body.AppendLine("<td>" + (int)item.TableItem6 + "</td>");
body.AppendLine("</td>");
}
body.AppendLine("</table>");
body.AppendLine("</body></html>");
return body.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment