1

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Mateusz Rogulski
  • 7,357
  • 7
  • 44
  • 62
  • possible duplicate of [How to embed images in email](http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email) – Paolo Moretti Jun 24 '12 at 13:05

2 Answers2

6

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

esertbas
  • 476
  • 3
  • 7
0

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.

Shyju
  • 214,206
  • 104
  • 411
  • 497