在主机名中插入额外

在主机名中插入额外

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

问题描述

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

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("[email protected]");
    mail.Subject = "Test";
    mail.From = new System.Net.Mail.MailAddress("[email protected]");
    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 发送者:[email protected]

X 接收器:[email protected]

X-Receiver: [email protected]

MIME 版本:1.0

MIME-Version: 1.0

发件人:[email protected]

From: [email protected]

致:[email protected]

To: [email protected]

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

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

主题:测试

内容类型:文本/纯文本;charset=us-ascii

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

内容传输编码:引用打印

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).请注意,如果我删除多余的空格(在is a"中),则 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 客户端会检查该行的第一个字符.如果是句号,则在行首插入一个句号.

.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 文件?在主机名中插入额外的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:50