C # mail delivery (with attachments)

Source: Internet
Author: User
Tags mailmessage smtpclient

classSendEmail {Static voidMain (string[] args) {            string  from="Sender @yingu.com"; stringFromer ="Zhaohai"; stringto ="recipient @yingu.com"; stringToer ="Liu Chun Xi"; stringSubject ="Overdue Data Report"; stringFile =string. Concat (System.AppDomain.CurrentDomain.BaseDirectory,"reprotingtemp\\ List of overdue orders. xls"); stringBody ="Overdue Data Report"; //Enterprise Mailbox SMTP            stringSMTPHost ="smtp.qiye.163.com"; stringSmtpuser ="Sender @yingu.com"; stringSmtppass ="****** (sender's mailbox password)"; SendMail ( from, Fromer, to, Toer, Subject, Body, file, SMTPHost, Smtpuser, Smtppass); }        /// <summary>        ///C # send mail function/// </summary>        /// <param name= "from" >Sender's Mailbox</param>        /// <param name= "Fromer" >Sending Person</param>        /// <param name= "to" >recipients ' mailboxes</param>        /// <param name= "Toer" >Recipient</param>        /// <param name= "Subject" >Theme</param>        /// <param name= "Body" >content</param>        /// <param name= "file" >Accessories</param>        /// <param name= "SMTPHost" >SMTP Server</param>        /// <param name= "Smtpuser" >Email</param>        /// <param name= "Smtppass" >Password</param>        /// <returns></returns>        Private Static BOOLSendMailstringSfrom,stringSfromer,stringStostringStoer,stringSsubject,stringSbody,stringSfilestringSsmtphost,stringSsmtpuser,stringSsmtppass) {            ////set from and to addressesMailAddress from=Newmailaddress (Sfrom, Sfromer); MailAddress to=Newmailaddress (STO, stoer); ////Create a MailMessage objectMailMessage Omail =NewMailMessage ( from, to); ////Add Attachment            if(Sfile! ="") {OMAIL.ATTACHMENTS.ADD (NewAttachment (sfile)); }            ////Mail HeaderOmail.subject =Ssubject; ////email ContentOmail.body =Sbody; ////Mail Formatomail.isbodyhtml =false; ////The encoding used in the messageomail.bodyencoding = System.Text.Encoding.GetEncoding ("GB2312"); ////Set message priority to highOmail.priority =Mailpriority.high; ////Send mailSmtpClient client =NewSmtpClient (); ////client. useDefaultCredentials = false;Client. Host =Ssmtphost; //Enterprise mailbox need to set up a port, personal mailbox does not needClient. Port = -; Client. Credentials=NewNetworkCredential (Ssmtpuser, Ssmtppass); Client. Deliverymethod=smtpdeliverymethod.network; Try{client.                Send (Omail); return true; }            Catch(Exception err) {//Response.Write (Err. Message.tostring ());                return false; }            finally            {                ////Release ResourcesOmail.dispose (); }        }    }

C # mail delivery (with attachments)

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.