-3

メール本文に写真を入れてメールを送りたいです。私の最初の試みでは、画像は添付ファイルのように表示されます。表示されますが、最後に表示されます。写真をメール本文の中央に配置する必要があります。

私が使用したチュートリアルはlinkです。

私のコードは次のようになります。

    mail.Body = "string htmlBody = \"<html><body><h1><center><img src=\"C:\\picture.png\"/></h1></html>";
    string contentID = "image1";
    Attachment inline = new Attachment("C:\\picture.png");
    inline.ContentDisposition.Inline = true;
    inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
    inline.ContentId = contentID;
    inline.ContentType.MediaType = "image/png";
    inline.ContentType.Name = "C:\\picture.png";
    mail.Attachments.Add(inline);
    mail.IsBodyHtml = true;
4

1 に答える 1

1

本当にチュートリアルに従った場合、次のコードが表示されます。

email.Body = "[...]<img src=\"@@IMAGE@@\" alt=\"\">";

// generate the contentID string using the datetime
string contentID = Path.GetFileName(attachmentPath).Replace(".", "");

Attachment inline
[...]
inline.ContentId = contentID;
[...]
email.Attachments.Add(inline);

// replace the tag with the correct content ID
email.Body = email.Body.Replace("@@IMAGE@@", "cid:" + contentID);

もちろん<img src="C:\picture.png">、メールを受信するユーザーは、Web メールを使用している場合はもちろん、PC のそのパスにその画像を持っていない可能性が高いため、使用は機能しません。

于 2012-06-28T09:07:11.673 に答える