0

I see some question closed by administrator with similar question. I will try to explain in detail the solution I'm looking for:

First I'm trying to develop a windows console application.

Sending frequency: monday to friday

How many users: from 5 to 20

Format of data: A table where rows are countries and columns different types of products and the cells represent the sale of that country-product

Limitation: Service users prefer not to use a pdf or excel or attachment of any type should be a html format possible to show in the body of mail

Currently I am creating the report almost artisan with something like:

.....
var myStringBuilder = new StringBuilder("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
myStringBuilder.Append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
myStringBuilder.Append("</head><body>");
myStringBuilder.AppendLine();
myStringBuilder.Append("<table style=\"font-family: Calibri; text-align: right; font-size: x-small;\">");
myStringBuilder.AppendLine();
var header = new StringBuilder("<tr><th>a</th><th>CATEG1</th><th>CATEG2</th><th>CATEG3</th><th>CATEG4</th><th>TOTAL</th></tr>");
var line = new StringBuilder("<tr><td>a</td><td>b</td><td>c</td><td>z</td><td>e</td><td>f</td></tr>");
foreach (var a in _actuals)
        {
            line.Replace("a", a.CountryName);
            if(a.Segment.ToLowerInvariant().Equals("categ1")) {
               line.Replace("b", "[" + string.Format("{0:0,#}", a.LsvLcFact / 1000) + "]"); }
            else if (a.Segment.ToLowerInvariant().Equals("categ2")) {
               line.Replace("c", "[" + string.Format("{0:0,#}", a.LsvLcFact / 1000) + "]"); }
            else if (a.Segment.ToLowerInvariant().Equals("categ3")) {
               line.Replace("z", "[" + string.Format("{0:0,#}", a.LsvLcFact / 1000) + "]"); } 
            else {
               line.Replace("e", "[" + string.Format("{0:0,#}", a.LsvLcFact / 1000) + "]"); }
          }
 .....

And in the class to send mail something like:

    public void SendResumen(string subject ,StringBuilder content)
    {
        var oMsg = new MailMessage...;
        ... add users
        oMsg.Subject = subject;
        var mimeType = new ContentType("text/html");
        var alternate = AlternateView.CreateAlternateViewFromString(content.ToString(), mimeType);
        oMsg.AlternateViews.Add(alternate);
        oMsg.IsBodyHtml = true;
        var cli = Client();
        cli.Send(oMsg);
    }

Finally, I hope you understand what I'm doing and the question is: Is there a tool I can use to not generate as crafted the message body?

4

2 回答 2

0

我接受@Jim-Mischel 的建议

于 2013-05-13T17:43:55.143 回答
0

我有一个 VB 应用程序,它可以发送具有 HTML 有效负载的消息,但它不使用 AlternateView 功能。

Dim mail As New MailMessage(fromUser.Email, toUser.Email)
mail.Subject = subject
mail.IsBodyHtml = True
mail.Body = message

虽然对那些无法读取 HTML 有效负载的电子邮件客户端使用 AlternateView 功能会很好,但您的代码不能真正使用它,因为您只提供了 HTML 消息。如果您确实设法让 AlternateView 功能在这里工作,那么任何无法读取 HTML 的客户端都会看到 HTML 标记,而不仅仅是简单的消息文本。为此,我认为您需要同时提供文本和 HTML 电子邮件正文。

于 2013-05-08T17:01:35.723 回答