2016-12-06 4 views
2

MailOutlookC#で送信したいのですが、私のAttachmentsの配置に問題があります。RTFメールの添付ファイルの配置

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 Arialの私は、次のコードを持っています{\ colortbl; \ red255 \ green0 \ blue128; \ red0 \ green128 \ blue255;} \ viewkind4 \ uc1 \ pard \ fs20ダレン\ cf0と\ cf2ヘレン\ cf0、\パー \パー hier ihre AB \ fs20 \ par }

私のMailは次のようになります。

RTF Mail Body

今私の質問は、

  1. AttachmentsはメールがRTFフォーマットされていないときのような余分な行として表示することができますか?
  2. 1.でない場合、どうすれば私のAttachmentsを最後に表示させることができますか?

答えて

1

あなたはすべてのことを正しく行いました。すべての値が1より大きい場合、添付ファイルはメールの最後に配置されます。 "hier ihre AB"の後に置かれます。愚かだがうまく見える... ちょっとした回避策として、私はあまりにもそれを使用し、いくつかの新しい行を配置します。添付書類を最後の文章の下に置くのに必要な分だけ。

または、メールをHTMLタイプとして記述します。少ない問題。

EDIT:あなたが見ることができるように

、ファイルがメールの最後に置かれています。

EDIT II:私は `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(); 
    } 
+0

:ここ

は、添付ファイルの行に添付ファイルをHTMLとしてあなたのEメールを送信する方法の例です。私のテキストは 'RichTextBox'から来て、' RTF'にあります。 'RTF'を' HTML'に変換するよい方法はありますか? –

+0

@ E-Nuffこのドキュメントは私に大いに助けてくれました:https://www.codeproject.com/kb/recipes/rtfconverter.aspx – Cataklysim

+0

Thnk you。最後の質問の1つは、添付ファイルが本文には表示されないが、通常のメールのように余分な行としてインストールされる可能性がありますか? –

関連する問題