【问题标题】:Emails (from asp.net System.Net.Mail) Truncating in Outlook but not Gmail电子邮件(来自 asp.net System.Net.Mail)在 Outlook 但不是 Gmail 中截断
【发布时间】:2016-01-25 21:49:33
【问题描述】:

我们正在运行一个较旧的 ASP.NET 2.5 应用程序,并且我们使用 System.Net.Mail 命名空间向客户发送纯文本电子邮件。有些有点长,因为我们会将正在更改的产​​品列表发送给我们的客户。

我们收到来自用户的报告,称他们的电子邮件被切断了。经过一番调查,我们意识到它们只是在 Outlook 中被切断了。在 Gmail 中,它们很好。知道这可能是什么吗?

这是生成我们电子邮件的代码的精简示例...

MailMessage msg = new MailMessage();
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["smtpHost"], Convert.ToInt16(ConfigurationManager.AppSettings["smtpPort"]));
client.Credentials = new    NetworkCredential(ConfigurationManager.AppSettings["smtpCredentialUser"], ConfigurationManager.AppSettings["smtpCredentialPassword"]);

msg.From = new MailAddress("xxx@xxxx.xxx", "Product Alert");
string Message_Subject = "Product Alerts";

string body = "\nThe following Products have been updated" + "\r\n\r\n";
    foreach (ProductItem pi in prods.updatedItems)
    {
        body += "Product Name: " + pi.Name.ToString() + "\n";
        body += "New Price   : " + pi.Price.ToString() + "\n";
    }

msg.Body = body;
msg.To.Add(new MailAddress("xxx@xxx.xxx","Mr. Test");

client.Send(msg);

【问题讨论】:

  • 这可能 100% 不相关,但我会尝试的第一件事是将您的消息编码更改为 UTF8,see this answer 了解如何

标签: c# asp.net email outlook


【解决方案1】:

问题可能与文本中的某些“特殊代码”字符有关,导致 Outlook 理解 EOF 或类似内容。

尝试将 BODYFORMAT 指定为 PLAINTEXT。

      msg.bodyformat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatPlain

【讨论】:

  • 我使用的 .Mail 版本没有 .bodyformat 属性。 IT 确实有 .IsBodyHtml 和 .BodyEncoding。我要和他们一起玩,看看有什么用。将按照上面的建议在那里尝试 UTF8。
  • 所以,只设置 .IsBodyHTML = false,因为您的消息是纯文本的。
猜你喜欢
  • 2014-12-12
  • 1970-01-01
  • 2011-06-08
  • 2014-06-06
  • 2022-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-02
相关资源
最近更新 更多