.NET 4.5 SMTP Client Dot Stuffing Issue upon delivery to the distribution directory

Hoping that someone can help with this, I look around and I can not find the answer anywhere.

I am creating an email message that will be delivered to the specified pickup directory, this code has been used many times in the past without any problems. Now, when I check the received file and, more specifically, the URL in the eml file, I see that there is a double in the middle . . From what I read, I understand that this is part of the SMTP protocol for the period if the first character of the line in the message starts with . . This file will later be picked up by another service that will eventually send the email.

I was able to narrow it down to the exact line when I call client.Send() . If I check the body of the message before sending, the URL will be correctly formed. Checking the body of the message after I called it, the URL is present ..

My question or questions, which I believe are as follows:

  • Does anyone else encounter a point stuffing issue when using SmtpDeliveryMethod.SpecifiedPickupDirectory ?
  • Whose task is it to handle this correctly? .NET SMTP or a secondary service that selects this message later and sends it to the final destination?
  • Any tips on how to resolve this?

I have previously tried the approach described here , but it fails with numerous exceptions.

Basically I am looking for a way to save this eml file in a place on the disk that can be selected and sent later, my knowledge in C # is still quite limited, so there may be something simple, I just look, so any tips or recommendations were would be greatly appreciated!

I created a small sample code to try to recreate the problem, this is not the exact content that I use, but it shows that after sending through the client.Send () method there is 2 '..' at the beginning of the line.

 using (var client = new SmtpClient()) { client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; client.PickupDirectoryLocation = @"C:\temp"; var message = new MailMessage(); message.To.Add(new MailAddress(" alice@a.com ")); message.From = new MailAddress(" bob@b.com "); message.Subject = "Smtp Dot Stuffing Test"; message.Body = ".ABC.... .0.1.2.3.4.5.6.7.8.9"; client.Send(message); } 
+5
source share
1 answer

SmtpClient should not be byte-filled when saving to a file. This is only necessary when the message stream is actually β€œuploaded” to the SMTP server to prevent the DATA command from ending prematurely (which ends with the line: β€œ. \ R \ n”).

If SmtpClient is a byte filling when saving to a file, this is a very broken behavior.

Since this is not possible to get around if you are using System.Net.Mail (and I assume you are), I would recommend using MimeKit to create and save your message to a file.

Then, if you need to parse the message and send it via SMTP, you can use MailKit to do this.

+3
source

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


All Articles