【发布时间】:2014-03-21 16:33:40
【问题描述】:
我正在使用标准的 .NET SMTPClient 发送纯文本电子邮件 - 如下:
// Configure mail client
using (SmtpClient mailClient = new SmtpClient(AppConfig.SMTPServer))
{
mailClient.Credentials = new System.Net.NetworkCredential(AppConfig.SMTPUsername, AppConfig.SMTPPassword);
// Create the mail message
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(AppConfig.SMTPSenderEmail, AppConfig.SMTPSenderDisplay);
foreach (string recipient in recipients)
{
mailMessage.To.Add(new MailAddress(recipient));
}
mailMessage.Bcc.Add(new MailAddress(AppConfig.SMTPBC));
mailMessage.Subject = subject;
mailMessage.Body = body;
mailMessage.IsBodyHtml = false;
// Attachments
if (attachments != null && attachments.Any())
{
foreach (KeyValuePair<string, Byte[]> attachment in attachments)
{
MemoryStream memStream = new MemoryStream(attachment.Value);
mailMessage.Attachments.Add(new Attachment(memStream, attachment.Key));
}
}
mailClient.Send(mailMessage);
}
当通过 POP3 客户端发送时,发送的电子邮件具有预期的格式,然而当我通过 Azure SendGrid module 发送时,每个新行都加倍,因此每个新行都有两个空行源正文字符串中的一个。有谁知道如何规避这个问题,因为我需要(并且想要)使用 SendGrid。
我看到了这个非常相似的问题 SendGrid newline issue 但是修复与 PHP 相关 - 我需要 C# 中的等价物
【问题讨论】: