2

EWS を使用してインライン添付ファイル付きのメールを送信しています。

私はそれに次のコードを使用しています:

var attachment = attachments.AddFileAttachment(path);
attachment.ContentId = cid;
attachment.IsInline = true;
attachment.ContentType = "PNG/Image";

メッセージの HTML 本文には、次のフラグメントが含まれています

<img src=""cid:{cid}""></img>

ここで、{cid} はcidフィールドの値です。

Outlook でメールをチェックすると機能しますが、OWAではメッセージ本文に画像が表示されません。

EWS 経由でインライン画像を含むメールを送信して OWA で表示する正しい方法を教えてください。

4

1 に答える 1

2

以下のコードは私にとってはうまくいき、Outlook/OWA/Mobile でインラインの添付ファイルを見ることができます。

手順:

  1. contentid のプレースホルダーを含む HTML 本文

  2. そのプレースホルダーを実際の添付ファイル contentid に置き換えます

  3. 新しい添付ファイルを作成し、プロパティをインライン (true) および contentid (関連付けられた添付ファイルの実際の contentid) に設定します。

        string attachment = "c:\\inlineattachment.png";
    
        // Create an e-mail message using the ExchangeService.
        EmailMessage message = new EmailMessage(ExchangeServiceObject);
    
        // Subject
        message.Subject = "Email with inline attachments";
    
        // Message body with place holder for contentid
        message.Body = "Email body with inline attachment </br> <img src=\"cid:{0}\">";
        message.Body.BodyType = BodyType.HTML;
    
        // Replace the place holder with contentid
        // Random GUID is used to avoid name collision for contentids 
        string newGuid = Guid.NewGuid().ToString();
        message.Body = string.Format(message.Body, newGuid);
    
        // Create a new attachment and add necessary properties to make it inline
        message.Attachments.AddFileAttachment(attachment);
        message.Attachments[message.Attachments.Count - 1].IsInline = true;
        message.Attachments[message.Attachments.Count - 1].ContentId = newGuid;
    
        // Add recipeint
        message.ToRecipients.Add("recipient@domain.com");
    
        // Send the e-mail message and save a copy.
        message.SendAndSaveCopy();
    
于 2015-06-29T16:13:26.283 に答える