Running a net462 console app which is testing emails by sending them to disk.
I noticed a duplication of full stops under certain circumstances. Looking at the produced email text file it seems to be when the full stop is at the end of the line in the .eml file.
Code to reproduce:
In normal C# Program.cs file
using (SmtpClient smtpClient = new SmtpClient())
{
var message = new MailMessage
{
From = new MailAddress("[email protected]"),
Subject = "some subject"
};
message.To.Add(new MailAddress("[email protected]"));
string thisBodyHtml = "<html><body>123456789 123456789 123456789 123456789 123456789 123.</body></html>";
AlternateView alternateViewFromString2 = AlternateView.CreateAlternateViewFromString(thisBodyHtml, Encoding.Default, "text/html");
message.AlternateViews.Add(alternateViewFromString2);
message.IsBodyHtml = true;
smtpClient.Send(message);
}
With app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Dev\Temp\EmailTester" />
</smtp>
</mailSettings>
</system.net>
</configuration>
Produces file with two full stops at the end:
X-Sender: [email protected]
X-Receiver: [email protected]
MIME-Version: 1.0
From: [email protected]
To: [email protected]
Date: 7 Nov 2018 16:07:17 +0000
Subject: some subject
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
<html><body>123456789 123456789 123456789 123456789 123456789 123=
..</body></html>
This doesn't happen when using deliveryMethod="Network"
Does this bug also occur with .NET Core?
Is this is a bug about .NET Framework, the bug report should be entered here:
https://developercommunity.visualstudio.com/spaces/61/index.html
This repo doesn't track .NET Framework bugs.
I found it in a .net framework console app but it appears to be happening on a netcoreapp2.1 console app as well.
Program.cs:
using System.Net.Mail;
using System.IO;
using System.Text;
namespace test_proj
{
class Program
{
static void Main(string[] args)
{
var outDir = @"C:\Dev\Temp";
if(Directory.Exists(outDir) == false) Directory.CreateDirectory(outDir);
using (SmtpClient smtpClient = new SmtpClient())
{
var message = new MailMessage
{
From = new MailAddress("[email protected]"),
Subject = "some subject"
};
message.To.Add(new MailAddress("[email protected]"));
string thisBodyHtml = "<html><body>123456789 123456789 123456789 123456789 123456789 123.</body></html>";
AlternateView alternateViewFromString2 = AlternateView.CreateAlternateViewFromString(thisBodyHtml, Encoding.Default, "text/html");
message.AlternateViews.Add(alternateViewFromString2);
message.IsBodyHtml = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
smtpClient.PickupDirectoryLocation = outDir;
smtpClient.Send(message);
}
}
}
}
test_proj.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>
Produced email:
X-Sender: [email protected]
X-Receiver: [email protected]
MIME-Version: 1.0
From: [email protected]
To: [email protected]
Date: 7 Nov 2018 23:05:04 +0000
Subject: some subject
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<html><body>123456789 123456789 123456789 123456789 123456789 123=
..</body></html>
I appreciate it's not a show stopper, but it had me very confused earlier.
Any interest in debugging a bit @chestercodes ?
I can certainly give it a go!
Calling SmtpClient.Send() with DeliveryMethod set to SpecifiedPickupDirectory creates an MailWriter
https://github.com/dotnet/corefx/blob/92a697cc5f49f756f3066d750db265835d5e66b4/src/System.Net.Mail/src/System/Net/Mail/MailWriter.cs#L18-L23
which uses an EightBitStream to write the data to disk .