首页 文章

附件放置在RTF邮件中

提问于
浏览
2

我想通过 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具有以下 Value :

{\ rtf1 \ ansi \ ansicpg1252 \ deff0 \ deflang1031 {\ fonttbl {\ f0 \ fnil \ fcharset0 Arial;}} {\ colortbl; \ red255 \ green0 \ blue128; \ red0 \ green128 \ blue255;} \ viewkind4 \ uc1 \ pard \ fs20 Sehr geehrte \ cf1 Damen \ cf0 und \ cf2 Herren \ cf0,\ par \ par hier ihre AB \ fs20 \ par}

但我的 Mail 看起来像这样:

RTF Mail Body

现在我的问题是,

  • Attachments 可以显示为额外的行,就像邮件不是RTF格式的那样吗?

  • 如果不是1.,那么如何让我的 Attachments 显示在结尾?

1 回答

  • 1

    嗯,你做的一切都正确 . 每个值> 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();
        }
    

相关问题