2017-02-09 13 views
2

私のprevious questionから始まり、MimeMessageの本文を設定すると、添付ファイル、ボディーパーツ、およびすべての詳細が削除されます。どうすればこの問題を回避できますか?mimemessageの本文を設定すると他の詳細が削除されます

foreach (MimeKit.MimeEntity bodyPart in tnefMessage.BodyParts) 
{ 
    if (!bodyPart.IsAttachment) 
    { 
     using (MemoryStream ms = new MemoryStream()) 
     { 
      bodyPart.WriteTo(ms); 

      ms.Flush(); 
      ms.Position = 0; 
      using (StreamReader sr = new StreamReader(ms)) 
      { 
       //Read in the contents until we get to the rtf 
       string line; 
       while (!(line = sr.ReadLine()).StartsWith("{") && !line.StartsWith("\\")) { } 

       tnefMessage.Body = new MimeKit.TextPart("plain") 
       { 
        Text = RTFToText($"{line}{sr.ReadToEnd()}") 
       }; 
      } 
     } 
    } 
} 

static string RTFToText(string rtf) 
{ 
    string text = string.Empty; 
    System.Threading.Thread thread = new System.Threading.Thread(() => 
    { 
     using (System.Windows.Forms.RichTextBox rtb = new System.Windows.Forms.RichTextBox()) 
     { 
      rtb.Rtf = rtf; 
      text = rtb.Text; 
     } 
    }); 
    thread.SetApartmentState(System.Threading.ApartmentState.STA); 
    thread.Start(); 
    thread.Join(); 

    return text; 
} 

答えて

0

これは、あなただけのHTMLに身体を設定しているので、あなたが混在するようにそれを設定して、添付ファイルを再度追加する必要がある:

Multipart multipart = new Multipart("mixed"); 
multipart.Add(new MimeKit.TextPart("plain") 
{ 
    Text = RTFToText($"{line}{sr.ReadToEnd()}") 
}); 

foreach (MimeEntity attachment in tnefMessage.Attachments) 
{ 
    multipart.Add(attachment); 
} 

tnefMessage.Body = multipart; 
関連する問題