我要发送 Mail
通过Outlook
和 C#
但是我的 Attachments
的位置有问题.我有以下代码:
if (strBody.StartsWith(@"{\rtf"))
{
mailItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText;
mailItem.RTFBody = Encoding.UTF8.GetBytes(strBody);
mailItem.Attachments.Add(strAttachment, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, int.MaxValue, null);
}
else
{
mailItem.Body = strBody;
mailItem.Attachments.Add(strAttachment, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 1, null);
}
我的 strBody 具有以下值:
{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fcharset0 宋体;}} {\colortbl ;\red255\green0\blue128;\red0\green128\blue255;} \viewkind4\uc1\pard\fs20 Sehr geehrte\cf1 Damen\cf0 和\cf2 Herren\cf0 ,\par \par hier ihre AB\fs20\par
但是我的Mail
看起来像这样:
现在我的问题是,
- 可以
Attachments
显示为额外的行,例如当邮件不是 RTF 格式时? - 如果不是 1.,那我怎样才能得到我的
Attachments
显示在最后?
最佳答案
好吧,你做对了一切。每个 > 1 的值都会将附件放在邮件的末尾。在“hier ihre AB”之后放置。看起来很愚蠢,但很好...... 作为一个小的解决方法,我也这样使用它,放置一些新行。尽可能多地将附件放在你的最后一句话下面。
或者您将邮件编写为 HTML 类型。问题更少。
编辑:
如您所见,文件放在邮件的末尾。
编辑二:
下面是一个将附件行中的附件作为 HTML 发送电子邮件的方法示例:
static void Main(string[] args)
{
Outlook.Application tmpOutlookApp = new Outlook.Application();
Outlook.MailItem tmpMessage = (Outlook.MailItem)tmpOutlookApp.CreateItem(Outlook.OlItemType.olMailItem);
tmpMessage.HTMLBody = "Test";
String sDisplayName = "Test";
int iPosition = (int)tmpMessage.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
Outlook.Attachment oAttach = tmpMessage.Attachments.Add(@"C:\Test.txt", iAttachType, iPosition, sDisplayName);
tmpMessage.Subject = "Your Subject will go here.";
Outlook.Recipients oRecips = (Outlook.Recipients)tmpMessage.Recipients;
Outlook.Recipient tmpRecipient = (Outlook.Recipient)oRecips.Add("EMail");
tmpRecipient.Resolve();
tmpMessage.Send();
}
关于c# - RTF 邮件中的附件放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40992191/