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

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

问题描述

似乎NET的SmtpClient与在主机名额外点创建电子邮件如果点是出现在一个MIME烯codeD行的开头(例如test.com有时显示为test..com )。例如:code:

  [TestMethod的]
公共无效TestEmailIssue()
{
    VAR邮件=新System.Net.Mail.MailMessage();
    VAR smtpClient =新System.Net.Mail.SmtpClient();

    mail.To.Add(Test@test.com);
    mail.Subject =测试;
    mail.From =新System.Net.Mail.MailAddress(test@test.com);
    mail.Body =你好,这是问题的一个简短的测试:
             +&所述; A HREF ='的https://test.com/'>的https://test.com/< / a取代;:;

    smtpClient.PickupDirectoryLocation =C:\\ \\温度;
    smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
    smtpClient.Send(邮件);
}
 

这将创建一个.eml文件看起来是这样的:

  

X-发件人:test@test.com

     

X-接收器:Test@test.com

     

MIME-版本:1.0

     

从:test@test.com

     

要:Test@test.com

     

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

     

主题:测试

     

的Content-Type:text / plain的;字符集= US-ASCII

     

内容传送编码:带引号的可打印      

您好,这是问题的一个简短的测试:https://开头的测试=

     

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

在发送文件,或打开Outlook中(或任何其他程序),双点出现(即test..com)。需要注意的是,如果删除了额外的空间(在是),即test.com正确显示自点不再出现在该行的开头。

这会导致一个问题,试图发送网页地址时,我们得到这样说,他们无法点击我们的链接,从客户端的调用。

任何人都经历呢?我们怎样才能解决这个问题,除了编写我们自己的编码?

解决方案

这其实是每个的 RFC 2821

  

在发送线邮件文本中,SMTP客户端检查该行的第一个字符。如果它是一个时期,一个附加周期被插入在该行的开头。

的.Net只是存储在准备好发送的模式,这意味着它不发送前必须猴与电子邮件的文件,而不是它能够传输原样。不幸的是这种格式不是100%相同的Outlook例preSS的EML格式显然。你应该能够将编码设置为UTF-8(或类似的东西),这将在BASE-64编码踢你。

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

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);
}

This creates an .eml file that looks like this:

X-Sender: test@test.com

X-Receiver: Test@test.com

MIME-Version: 1.0

From: test@test.com

To: Test@test.com

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

Subject: Test

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

Content-Transfer-Encoding: quoted-printable

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

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

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?

解决方案

This is actually per RFC 2821

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 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天全站免登陆