Search code examples
c#emailwebmail

How can I display images in mail content?


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.


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