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では画像がメッセージ本文に表示されません。
EWAを介してインライン画像付きのメールを送信してOWAで表示する正しい方法を教えてください。
以下のコードは私にとってはうまくいき、Outlook / OWA / Mobileでインライン添付ファイルを見ることができます。
手順:
contentidsのプレースホルダーを含むHTML本文
そのプレースホルダーを実際の添付コンテンツIDに置き換えます
新しい添付ファイルを作成し、プロパティをインライン(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("[email protected]");
// Send the e-mail message and save a copy.
message.SendAndSaveCopy();