Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top