CSL*_*CSL 4 c# email azure sendgrid
我使用标准的.NET SMTPClient发送PLAIN文本电子邮件 - 如下所示:
// 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);
}
Run Code Online (Sandbox Code Playgroud)
当通过POP3客户端发送时,发送的电子邮件具有预期的格式,但是当我通过发送时Azure SendGrid module
,每个新行都加倍,因此源体字符串中的每一行都有两个空行.有没有人知道如何绕过这个问题,因为我需要(并希望)使用SendGrid.
我看到这个非常相似的问题SendGrid换行问题然而修复与PHP有关 - 我需要在C#中的等价物
好的,经过几个小时的调查,在发布问题后的5分钟内我找到了答案并且非常简单,将其添加到邮件客户端配置中可以完美地排序问题:
mailMessage.BodyEncoding = Encoding.UTF8;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1668 次 |
最近记录: |