You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
In my use case i am dkiming an email, then sending it using the SmtpClient, SMTP client appears to be adding an extra newline to the end of the message/rfc822 attachment in the email (see example) thus breaking the dkim signature. My understanding is that after calling message.Prepare the email body should not need to be modified further when sending (allowing you to dkim it).
To Reproduce
The following is a C# console app that once MailKit is installed should run fine
using System;using System.Collections.Generic;using System.IO;using System.Text;using System.Text.RegularExpressions;using System.Threading.Tasks;using AngleSharp;using AngleSharp.Dom;using AngleSharp.Html.Parser;using MailKit.Net.Smtp;using MailKit.Security;using MimeKit;namespaceTesting{classProgram{staticasync Task Main(string[]args){varmessage= MimeMessage.Load(new MemoryStream(Encoding.UTF8.GetBytes(@"From: [email protected]Date: Fri, 15 Feb 2019 16:00:08 +0000Subject: report_with_no_bodyTo: [email protected]MIME-Version: 1.0Content-Type: multipart/report; report-type=delivery-status; boundary=""A41C7.838631588=_/mm1""Processing your mail message caused the following errors:error: err.nosuchuser: [email protected]--A41C7.838631588=_/mm1Content-Type: message/delivery-statusReporting-MTA: dns; mm1Arrival-Date: Mon, 29 Jul 1996 02:12:50 -0700Final-Recipient: RFC822; [email protected]Action: failedDiagnostic-Code: X-LOCAL; 500 (err.nosuchuser)--A41C7.838631588=_/mm1Content-Type: message/rfc822Received: from urchin.netscape.com ([198.95.250.59]) by mm1.sprynet.com with ESMTP id <148217-12799>; Mon, 29 Jul 1996 02:12:50 -0700Received: from gruntle (gruntle.mcom.com [205.217.230.10]) by urchin.netscape.com (8.7.5/8.7.3) with SMTP id CAA24688 for <[email protected]>; Mon, 29 Jul 1996 02:04:53 -0700 (PDT)Sender: [email protected]Message-ID: <[email protected]>Date: Mon, 29 Jul 1996 02:04:52 -0700From: Jamie Zawinski <[email protected]>Organization: Netscape Communications Corporation, Mozilla DivisionX-Mailer: Mozilla 3.0b6 (X11; U; IRIX 5.3 IP22)MIME-Version: 1.0To: [email protected]Subject: unsubscribeReferences: <[email protected]>Content-Type: text/plain; charset=us-asciiContent-Transfer-Encoding: 7bitunsubscribe--A41C7.838631588=_/mm1--")));//prepare before dkim
message.Prepare(EncodingConstraint.EightBit);// Im not actually going to dkim the email here as that should not make a difference to the result of this and i would need to pull in certs etc.. // write the message to console, notice that after unsubscribe in the message/rfc822 part there is no new line.
Console.WriteLine("Message after being prepared");using(varstream=new MemoryStream()){
message.WriteTo(stream);
stream.Position =0;
Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray()));}// now send emailusing(varstream=new MemoryStream()){varclient=new SmtpClient(new MailKit.ProtocolLogger(stream,true)){SslProtocols= System.Security.Authentication.SslProtocols.Tls12,LocalDomain="localhost"};await client.ConnectAsync("localhost",25, SecureSocketOptions.Auto);await client.SendAsync(message, MailboxAddress.Parse("me@localhost"),newList<MailboxAddress>{MailboxAddress.Parse("me@localhost")});
client.Disconnect(true);
Console.WriteLine("SMTP logs");
Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray()));}
Console.ReadLine();}}}
Output of this program:
Message after being prepared
From: [email protected]
Date: Fri, 15 Feb 2019 16:00:08 +0000
Subject: report_with_no_body
To: [email protected]
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status; boundary="A41C7.838631588=_/mm1"
Processing your mail message caused the following errors:
error: err.nosuchuser: [email protected]
--A41C7.838631588=_/mm1
Content-Type: message/delivery-status
Reporting-MTA: dns; mm1
Arrival-Date: Mon, 29 Jul 1996 02:12:50 -0700
Final-Recipient: RFC822; [email protected]
Action: failed
Diagnostic-Code: X-LOCAL; 500 (err.nosuchuser)
--A41C7.838631588=_/mm1
Content-Type: message/rfc822
Received: from urchin.netscape.com ([198.95.250.59]) by mm1.sprynet.com with ESMTP id <148217-12799>; Mon, 29 Jul 1996 02:12:50 -0700
Received: from gruntle (gruntle.mcom.com [205.217.230.10]) by urchin.netscape.com (8.7.5/8.7.3) with SMTP id CAA24688 for <[email protected]>; Mon, 29 Jul 1996 02:04:53 -0700 (PDT)
Sender: [email protected]
Message-ID: <[email protected]>
Date: Mon, 29 Jul 1996 02:04:52 -0700
From: Jamie Zawinski <[email protected]>
Organization: Netscape Communications Corporation, Mozilla Division
X-Mailer: Mozilla 3.0b6 (X11; U; IRIX 5.3 IP22)
MIME-Version: 1.0
To: [email protected]
Subject: unsubscribe
References: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
unsubscribe
--A41C7.838631588=_/mm1--
SMTP logs
Connected to smtp://localhost:25/?starttls=when-available
S: 220 DESKTOP-6BUQHK5 ESMTP SubEthaSMTP null
C: EHLO localhost
S: 250-DESKTOP-6BUQHK5
S: 250-8BITMIME
S: 250-AUTH LOGIN
S: 250 Ok
C: MAIL FROM:<me@localhost>
S: 250 Ok
C: RCPT TO:<me@localhost>
S: 250 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: [email protected]
C: Date: Fri, 15 Feb 2019 16:00:08 +0000
C: Subject: report_with_no_body
C: To: [email protected]
C: MIME-Version: 1.0
C: Content-Type: multipart/report; report-type=delivery-status; boundary="A41C7.838631588=_/mm1"
C:
C:
C: Processing your mail message caused the following errors:
C:
C: error: err.nosuchuser: [email protected]
C:
C: --A41C7.838631588=_/mm1
C: Content-Type: message/delivery-status
C:
C: Reporting-MTA: dns; mm1
C: Arrival-Date: Mon, 29 Jul 1996 02:12:50 -0700
C:
C: Final-Recipient: RFC822; [email protected]
C: Action: failed
C: Diagnostic-Code: X-LOCAL; 500 (err.nosuchuser)
C:
C: --A41C7.838631588=_/mm1
C: Content-Type: message/rfc822
C:
C: Received: from urchin.netscape.com ([198.95.250.59]) by mm1.sprynet.com with ESMTP id <148217-12799>; Mon, 29 Jul 1996 02:12:50 -0700
C: Received: from gruntle (gruntle.mcom.com [205.217.230.10]) by urchin.netscape.com (8.7.5/8.7.3) with SMTP id CAA24688 for <[email protected]>; Mon, 29 Jul 1996 02:04:53 -0700 (PDT)
C: Sender: [email protected]
C: Message-ID: <[email protected]>
C: Date: Mon, 29 Jul 1996 02:04:52 -0700
C: From: Jamie Zawinski <[email protected]>
C: Organization: Netscape Communications Corporation, Mozilla Division
C: X-Mailer: Mozilla 3.0b6 (X11; U; IRIX 5.3 IP22)
C: MIME-Version: 1.0
C: To: [email protected]
C: Subject: unsubscribe
C: References: <[email protected]>
C: Content-Type: text/plain; charset=us-ascii
C: Content-Transfer-Encoding: 7bit
C:
C: unsubscribe
C:
C: --A41C7.838631588=_/mm1--
C: .
S: 250 Ok
C: QUIT
S: 221 Bye
When running this you will see when the message is written our hte first time after preparing it there is no new line after unsubscribe (in the message/rfc822 part). However when sending it there is a new line after unsubscribe in the SMTP logs. Expected behavior
There should be no difference in the email body between prepaeiring it as otherwise any attempt at dkiming is useless as when the next party received the email the dkim body signature will not match.
Desktop (please complete the following information):
OS: Windows 10
dotnet version: dotnet core V2.2
Additional context
I only have reproduce the issue with this sample attached above but i have seen similar symptoms in emails with other attachments as well.
The text was updated successfully, but these errors were encountered:
jstedfast
changed the title
SmtpClient Adding extra newline to embedded attachments upon saving.
SmtpClient adding an extra newline to the end of embedded message/rfc822 attachments when sending.
Oct 2, 2019
jstedfast
changed the title
SmtpClient adding an extra newline to the end of embedded message/rfc822 attachments when sending.
Extra newline added to the end of embedded message/rfc822 attachments when sending via SmtpClient
Oct 2, 2019
Describe the bug
In my use case i am dkiming an email, then sending it using the SmtpClient, SMTP client appears to be adding an extra newline to the end of the message/rfc822 attachment in the email (see example) thus breaking the dkim signature. My understanding is that after calling message.Prepare the email body should not need to be modified further when sending (allowing you to dkim it).
To Reproduce
The following is a C# console app that once MailKit is installed should run fine
Output of this program:
SMTP logs
When running this you will see when the message is written our hte first time after preparing it there is no new line after unsubscribe (in the message/rfc822 part). However when sending it there is a new line after unsubscribe in the SMTP logs.
Expected behavior
There should be no difference in the email body between prepaeiring it as otherwise any attempt at dkiming is useless as when the next party received the email the dkim body signature will not match.
Desktop (please complete the following information):
Additional context
I only have reproduce the issue with this sample attached above but i have seen similar symptoms in emails with other attachments as well.
The text was updated successfully, but these errors were encountered: