Introduction

This article describes how to send an email with an image in C#. For sending the email, you need to configure the email services on the server.

Note. For more info about configuration read how to configure mail server (http://technet.microsoft.com/en-us/library/cc780996%28v=ws.10%29.aspx).

To explain this article, I will use the following procedure after configuring the server.

The following procedure is the details of the preceding steps.

Step 1. Create a new empty Website named "MailServer".

MailServer

Step 2

Note. The "SmtpMail.Host" value will be your hosting name or IP Address and the "SmtpMail.Port" will also vary.

SmtpMail.Host

private AlternateView Mail_Body()
{
    string path = Server.MapPath(@"Images/photo.jpg");
    LinkedResource Img = new LinkedResource(path, MediaTypeNames.Image.Jpeg);
    Img.ContentId = "MyImage";
    string str = @"
        <table>
            <tr>
                <td> '" + txtmessagebody.Text + @"' 
                </td>
            </tr>
            <tr>
                <td>
                    <img src=cid:MyImage  id='img' alt='' width='100px' height='100px'/>   
                </td>
            </tr></table>
            ";
    AlternateView AV =   
    AlternateView.CreateAlternateViewFromString(str, null, MediaTypeNames.Text.Html);
    AV.LinkedResources.Add(Img);
    return AV;
}

Mail

Step 3

Result

Now you can see that I (the receiver) got the email.

Receiver