Popular Posts
Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... CTE, recursive search WITH DepartmentSearch(DeptID, DeptParent, DeptName, OuID) AS (     -- 找出簽核者所屬部門     SELECT d.DeptID, d.DeptParent, d.DeptName, d.OuID     FR... Create web service client cross SSL with eclipse When creating web service cross SSL using eclipse, it occuss some error like below: And it can't build the client source from this wa...
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);

}