c# - 在 .NET 中向电子邮件添加内容描述
问题描述
我正在尝试在电子邮件中设置 MIME 内容描述字段。我使用 AlternateView 设置了 Content-Type 和 Content-Transfer-Encoding,但我找不到添加 Content-Description 的方法。
我可以做的是使用自定义标头设置 Content-Description,但这似乎为整个电子邮件插入单个 Content-Description,而不是 MIME 对象。
using( MailMessage mailMessage = new MailMessage() )
{
mailMessage.From = new MailAddress( _configuration.FromAddress );
mailMessage.BodyEncoding = Encoding.UTF8;
mailMessage.To.Add( to );
mailMessage.Subject = subject;
// add the MIME data
var irisB2View = AlternateView.CreateAlternateViewFromString( body );
irisB2View.ContentType = new ContentType( "Application/EDI-consent" ); // Content-Type
irisB2View.TransferEncoding = TransferEncoding.Base64; // Content-Tranfer-Encoding
mailMessage.AlternateViews.Add( irisB2View );
// this adds Content-Description, but it appears before the MIME data
mailMessage.Headers.Add( "Content-Description", "IRIS/B2/Z" );
client.Send( mailMessage );
}
这会产生如下形式的电子邮件,在 MIME 对象之前带有 Content-Description:
Content-Description: IRIS/B2/Z
MIME-Version: 1.0
From: xxxxxx@xxxxxx.xx
To: xxxxxx@xxxxxx.xx
Date: 28 Sep 2018 13:49:51 +0200
Subject: subject
Content-Type: Application/EDI-consent
Content-Transfer-Encoding: base64
有人知道我如何设法将 Content-Description 放入 MIME 内容中吗?
同样,邮件没有边界(我只有一个 MIME 对象),那么 Content-Description 在 MIME 对象之前是否真的很重要?
提前致谢。
解决方案
RFC 2045 指定在单个部分消息中,MIME 标头字段在常规 RFC 822 标头的上下文中使用。RFC 822 没有对标头字段施加顺序。因此 Content-Description 字段的位置并不重要。
推荐阅读
- android - 如果一开始没有互联网,如何在(分页数据流)中再次触发
- json - lagom 问题 org.json.simple.JsonObject 转换为 scala.immutable.Map$2Map compleatedFuture()
- android - 通过 system.IO.FileNotFoundException 在 xamarin 中使用 .net 进行单元测试无法加载文件或程序集“xamarin.forms.core”2.0.0.0
- python - A* 算法 TypeError: cannot unpack non-iterable int object
- flutter - 当我试图在方法中调用它时未定义的名称“_change”| 扑
- go - Google-speech-api 抛出 EOF 错误而不是执行音频转录
- java - 如何从 HttpServlet 框架的堆栈中获取有关 HTTP 请求的信息
- c++ - 来自 harry 的 YouTube 频道的代码教程
- javascript - 如何添加对象值的总和并合并数组对象?
- react-native - 在 reactnative expo 中,我尝试在 redux 中使用 expo 中的 secureStore 来保存我从 api 获得的令牌