RTF 邮件中的附件放置

Attachment placement in a RTF Mail

我想通过 OutlookC# 发送 Mail,但我的 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 und \cf2 Herren\cf0 ,\par \par 我在这里 AB\fs20\par }

但是我的 Mail 看起来像这样:

现在我的问题是,

  1. Attachments 是否可以像非 RTF 格式的邮件一样显示为额外的行?
  2. 如果不是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();
    }