C # Mail sending feature

Source: Internet
Author: User

Unified by one mailbox to send the employment notice string strfrom = "";//Sender's mailbox address string strpow = "";//Mailbox Password string strserver            = "";//Send mail server string strto = "";//Recipient address string strtitle = "Mail Header"; String strdody = "<div style= ' font-size:14px; '            > Email Content </div> "; string file1 = Server.MapPath ("attachment. Doc");//Attachment address 1 string file2 = Server.MapPath ("attachment. pdf");//Attachment Address 2//Send            Mail Methods//send (strserver, Strfrom, Strpow, Strto, strtitle, strdody);            SmtpClient client = new SmtpClient (strserver); Client.            useDefaultCredentials = false; Client.            useDefaultCredentials = true; Client.            Credentials = new System.Net.NetworkCredential (strfrom, Strpow); Client.            Deliverymethod = Smtpdeliverymethod.network;            Byte[] B = Encoding.Default.GetBytes (strdody); Strdody = encoding.getencoding ("gb2312"). GetString (b).            ToString (); Create an object of the message attachment class with the syntax format System.Net.Mail.AttachmenT (filename, file format) System.Net.Mail.Attachment myAttachment1 = new System.Net.Mail.Attachment (File1, Syst Em.            Net.Mime.MediaTypeNames.Application.Octet); System.Net.Mail.Attachment MyAttachment2 = new System.Net.Mail.Attachment (file2, System.Net.Mime.MediaTypeName            S.application.octet);                        MailMessage message = new MailMessage (strfrom, Strto, strtitle, strdody); Message. Attachments.Add (myAttachment1);//Use the Attachments attribute in the SmtpClient object to add the Myattachment message set above.            Attachments.Add (MyAttachment2); Message.            bodyencoding = Encoding.UTF8; Message.            Isbodyhtml = true; Client. Send (message);

There are many default methods in sending mail, and if you have any problems, update them at any time!

C # Mail sending feature

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.