質問

I want send e-mail with some images in content. I think I must attached this images as attachments to e-mail, but my proble is how can I use attached images in mail content?

CODE WHICH SEND MAIL

WebMail.SmtpServer = "my.smtp.server";
WebMail.Send(
        clientEmail,
        subject,
        "<html><head></head><body><img src='???' /></body></html>",
        myEmail,
        null,
        new List<string> () { "path" },
        true
    );

What I must write as src ?

Any help would be appreciated.

役に立ちましたか?

解決

Also good sample at http://blog.devexperience.net/en/12/Send_an_Email_in_CSharp_with_Inline_attachments.aspx

System.Net.Mail.Message Class :

Sample ;

var msg = new System.Net.Mail.Message();
msg.isHTML=true;
msg.Body ="<img src=\"cid:IMG1CONTENT\">";


Attachment mya = new Attachment("file-path-here");
mya.ContentId="IMG1CONTENT";
msg.Attachments.Add(mya);

You can find more details @ http://msdn.microsoft.com/en-us/library/system.net.mail.attachment.aspx

他のヒント

To display the images in email content, one solution is to have an absolute URL. Upload the images to your server and use the abosoluter url as the src attribute value

<img src='http://www.yourdomain.com/youfolder/image.jpg' alt='your image desc'/>

But some email clients will disable external images. So user may need to enable "show images" when propmpted so.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top