System.Net.Mail创建无效的电子邮件和eml文件?在主机名中插入多个点 [英] System.Net.Mail creating invalid emails and eml files? Inserting extra dots in host names

查看:151
本文介绍了System.Net.Mail创建无效的电子邮件和eml文件?在主机名中插入多个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎.NET的SmtpClient正在创建在主机名中带有额外点的电子邮件,如果点出现在MIME编码行的开头(例如,test.com有时显示为test..com)。示例代码:

It appears that .NET's SmtpClient is creating emails with an extra dot in host names if the dot was to appear at the beginning of a MIME encoded line (e.g. test.com sometimes shows up as test..com). Example code:

[TestMethod]
public void TestEmailIssue()
{
    var mail = new System.Net.Mail.MailMessage();
    var smtpClient = new System.Net.Mail.SmtpClient();

    mail.To.Add("Test@test.com");
    mail.Subject = "Test";
    mail.From = new System.Net.Mail.MailAddress("test@test.com");
    mail.Body = "Hello this is  a short test of the issue:"
             +" <a href='https://test.com/'>https://test.com/</a>: ";

    smtpClient.PickupDirectoryLocation = "C:\\temp\\";
    smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
    smtpClient.Send(mail);
}

这将创建一个.eml文件,如下所示:

This creates an .eml file that looks like this:


X-Sender:test@test.com

X-Sender: test@test.com

X-Receiver:Test@test.com

X-Receiver: Test@test.com

MIME版本:1.0

MIME-Version: 1.0

来自:test@test.com

From: test@test.com

To:Test@test.com

To: Test@test.com

日期:2011年7月6日15:55:28 -0400

Date: 6 Jul 2011 15:55:28 -0400

主题:测试

Content-Type:text / plain; charset = us-ascii

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding:quoted-printable

Content-Transfer-Encoding: quoted-printable

你好这是一个简短的测试的问题:https:// test =

Hello this is a short test of the issue: https://test=

.. com /'> https://test.com/ := 20

..com/'>https://test.com/:=20

发送文件或在Outlook中打开(或任何其他程序),双点出现(即test..com)。请注意,如果我删除额外的空间(在是),那么该test.com将显示正确,因为该点不再出现在该行的开始。

When sending the file, or opening in Outlook (or any other program), the double dots show up (i.e. test..com). Note that if I remove the extra space (in "is a"), that test.com shows correctly since the dot no longer appears at the beginning of the line.

这会在尝试发送网站地址时出现问题,我们从客户端收到来电,表示不能点击我们的链接。

This causes a problem when trying to send website addresses, and we get calls from clients saying this they cannot click our links.

有没有人经历过这个?我们如何解决这个问题,而不是编写自己的编码?

Has anyone else experienced this? How can we resolve this issue other than writing our own encoding?

推荐答案

这实际上是根据 RFC 2821 (4.5.2透明度)

This is actually per RFC 2821 (4.5.2 Transparency)


在发送一行邮件文本之前,SMTP客户端会检查该行的第一个字符。如果是一个期间,则在行的开头插入一个额外的期间。

Before sending a line of mail text, the SMTP client checks the first character of the line. If it is a period, one additional period is inserted at the beginning of the line.

.Net只是将文件存储在准备发送模式,这意味着它不需要在发送之前将电子邮件猴子,而是可以按原样发送。不幸的是,这种格式与Outlook Express的EML格式显然不是100%相同。您应该可以将编码设置为UTF-8(或类似的内容),并将为您启用Base-64编码。

.Net is just storing the file in "ready to transmit" mode which means that it doesn't have to monkey with the email before sending, instead it can transmit it as is. Unfortunately this format isn't 100% the same as Outlook Express's EML format apparently. You should be able to set the encoding to UTF-8 (or something similar) and that will kick in Base-64 encoding for you.

mail.BodyEncoding = System.Text.Encoding.UTF8;

这篇关于System.Net.Mail创建无效的电子邮件和eml文件?在主机名中插入多个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆