c# - RTF 邮件中的附件放置

标签 c# outlook rtf

我要发送 Mail通过OutlookC#但是我的 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看起来像这样:

RTF Mail Body

现在我的问题是,

  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();
    }

关于c# - RTF 邮件中的附件放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40992191/

相关文章:

html - 从 Outlook 中的 URL 中删除 html 超链接

email - Powershell 中一项 Outlook 规则的多个操作

c# - 组合框下拉列表

c# - switch 中的多个字符串比较

outlook - 如何使用ics文件取消日历事件?

c++ - 如何以编程方式编写一些 RTF 格式的 unicode 文本?

php 到 rtf,é 变成 É

java - 使用java从domino获取rtf字段以获取JSON

c# - 以编程方式将相机置于 unity3d 中的对象上

c# - 《2048》的游戏开发者是如何让他们的方 block 移动流畅的?请参阅下面的详细信息