Additional lines in a regular text message via SendGrid

I am using the standard .NET SMTPClient to send a PLAIN text message as follows:

// 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);

        }

When sending through a POP3 client, the sent message has the expected format, however, when I send through Azure SendGrid module, each new line is doubled, so for each line of the source code there are two empty lines. Does anyone know how to get around this problem as needed (and want to) use SendGrid.

I see this very similar question, the problem with the new SendGrid line , however, the fix applies to PHP - I need an equivalent in C #

+4
source share
1 answer

, , 5 , , :

mailMessage.BodyEncoding = Encoding.UTF8;
+6

Source: https://habr.com/ru/post/1532868/


All Articles