我正在尝试创建一个TransportAgent
,将内部电子邮件重新路由到远程服务器进行进一步处理,但电子邮件以Microsoft的内部 TNEF 格式返回(未应用内容转换)。我希望它采用与电子邮件发送给外部收件人时使用的格式相同的格式。
我目前正在使用RoutingAgent
将内部电子邮件重新路由到远程服务器。如果有人能解释为什么会发生这种情况,即使我无法避免,那也将非常有帮助。此代理将同时针对 Exchange 2010 和 2013 实施,以防答案因 Exchange 版本而异。
Exemple using reflexion ItemConversion.convertAnyMimeToMimeMethod Method Method
var mimeDocument = new MimeDocument();
using (var mimeDocumentLoadStream = mimeDocument.GetLoadStream())
{
ConvertAnyMimeToMimeMethod(email.Message.MimeDocument, mimeDocumentLoadStream);
}
var convertedEmail = EmailMessage.Create(mimeDocument);
private static void ConvertAnyMimeToMimeMethod(MimeDocument documentIn, Stream mimeOut)
{
var assembly = Assembly.Load("Microsoft.Exchange.Data.Storage");
var outboundConversionOptionsType = assembly?.GetType("Microsoft.Exchange.Data.Storage.OutboundConversionOptions");
var outboundOptionsConstructor = outboundConversionOptionsType?.GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public,
null,
new[] { typeof(string) },
null);
var outboundOptions = outboundOptionsConstructor?.Invoke(new object[] { "OurDomain.tld" });
var itemConversionType = assembly?.GetType("Microsoft.Exchange.Data.Storage.ItemConversion");
var convertAnyMimeToMimeMethod = itemConversionType?.GetMethod(
"ConvertAnyMimeToMime",
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
null,
new[] { documentIn.GetType(), mimeOut.GetType(), outboundOptions?.GetType() },
null);
convertAnyMimeToMimeMethod.Invoke(null, new[] { documentIn, mimeOut, outboundOptions });
}