【问题标题】:Extra new lines in Plain text email via SendGrid通过 SendGrid 在纯文本电子邮件中增加新行
【发布时间】: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# 中的等价物

【问题讨论】:

    标签: c# email azure sendgrid


    【解决方案1】:

    好的,经过几个小时的调查,在发布问题后的 5 分钟内,我找到了答案,而且非常简单,将其添加到邮件客户端配置中可以完美地解决问题:

    mailMessage.BodyEncoding = Encoding.UTF8;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-17
      • 2016-03-02
      相关资源
      最近更新 更多