Popular Posts
CORS in Asp.net MVC Web API v2 Step 1. Install cors from NeGet Step 2. Enable cors in config using System; using System.Collections.Generic; using System.Linq; using ... DNS SERVER LIST Google 8.8.8.8 8.8.4.4 TWNIC 192.83.166.11 211.72.210.250 HiNet 168.95.1.1 168.95.192.1 Seednet 北區 DNS (台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗) 139.... Capture response output stream using HttpModule using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Web; namespace TestWebA...
Stats
Add attachment as inline resource when sending mail
static void Main(string[] args)
{
    // creat client instance
    SmtpClient client = new SmtpClient("smtp.mail.com", 25);

    // create mail message
    MailMessage message = new MailMessage();
    message.From = new MailAddress("from@mail.com", "I'm a sender");
    message.To.Add("to@mail.com");

    // create attachment instance
    Attachment attachment = new Attachment(@"C:\about-pic.gif");
    // set attachment name (for assign resource name later)
    attachment.Name = Path.GetFileName(@"C:\about-pic.gif");
    attachment.ContentId = "about_pic";
    // set attachment same to mail
    attachment.NameEncoding = message.BodyEncoding;
    attachment.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;

    // set attachment as embeded resources
    attachment.ContentDisposition.Inline = true;
    attachment.ContentDisposition.DispositionType = System.Net.Mime.DispositionTypeNames.Inline;


    message.Attachments.Add(attachment);
    message.Subject = "test attchement";
    message.Body = "<html><head><title>test attchemtn</title></head><body style='background-color:#aaaaff;'>"
        + "<h1>test attchement</h1><img src='cid:"+attachment.ContentId+"' /></body></html>";
    message.IsBodyHtml = true;
    client.Send(message);

}