C # send messages contain pictures

Source: Internet
Author: User

            List<string> to = new list<string> ();            To.add ("[email protected]");            list<string> CC = new list<string> (); Cc.            Add ("[email protected]");            MailMessage Message = new MailMessage ();            Message.isbodyhtml = true;            message.bodyencoding = Utf8encoding.utf8;            message.subjectencoding = Utf8encoding.utf8;            message.priority = Mailpriority.normal;            Message.sender = new MailAddress ("[email protected]");            Message.subject = "Test";            Message.from = new MailAddress ("[email protected]");            for (int i = 0; i < To.count; i++) {Message.To.Add (New mailaddress (To[i])); } for (int i = 0; i < CC. Count;            i++) {Message.CC.Add (New mailaddress (Cc[i]));            } message.body = Genmailbody (); Add Attachment Message.Attachments.Add (new atTachment ("c:\\aa.jpg")); Set attachment type Message.attachments[0].            Contenttype.name = "Image/jpg"; Set the attachment Id message.attachments[0].            ContentId = "Ewen"; Set the attachment to inline-inline message.attachments[0].            Contentdisposition.inline = true; Set the encoding format of the attachment Message.attachments[0].            transferencoding = System.Net.Mime.TransferEncoding.Base64;            SmtpClient client = new SmtpClient (); Client.            Host = "Smtp.local"; Client.            Deliverymethod = Smtpdeliverymethod.network;            BOOL Issend = false; try {client.            Send (Message); } catch (Exception E1) {//maillog (to, to, E1.            Message.tostring ()); }

is mainly

Message.attachments[0]. ContentId = "Ewen"
The ID set in the mail body should correspond to the SRC in the img tag
        public static string Genmailbody ()        {            StringBuilder sb = new StringBuilder ();            Sb. Append ("Dear suppliers:<br/>");            Sb. Append ("The recent Askey video, Asahi Import label, mainly due to the label serial ID code re-caused Askey can not be on the line, you are hereby notified suppliers special attention to this item!" <br/> ");            Sb. Append ("If you have any questions please e-mail to [email protected], [email protected]<br/>");            Sb. Append (" ");            Return SB. ToString ();        }

  

C # send messages contain pictures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.