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)