Runtime: [SmtpClient] Duplicate full stops with certain message length when using SpecifiedPickupDirectory

Created on 7 Nov 2018  路  6Comments  路  Source: dotnet/runtime

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"

area-System.Net bug up-for-grabs

All 6 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matty-hall picture matty-hall  路  3Comments

EgorBo picture EgorBo  路  3Comments

nalywa picture nalywa  路  3Comments

GitAntoinee picture GitAntoinee  路  3Comments

jzabroski picture jzabroski  路  3Comments