First, preface
Since the job needs to be recently packaged into WebService, the code is now documented here for later review.
Second, apart write code
Private void_sendmail (stringFormstringpwstringSubjectstring[] To,string[] cc,stringBodystringAttachmentName,byte[] attachment) {SmtpClient client=NewSmtpClient (SMTP service address, SMTP service port); Client. useDefaultCredentials=true; Client. Credentials=Newnetworkcredential (form, pw);//The client cannot be sent if the authentication information is consistent with the source address of the message sent. Deliverymethod=smtpdeliverymethod.network; MailMessage message=NewMailMessage (); Message. from=Newmailaddress (form); foreach(stringToiteminchTo ) {message.} To.add (Toitem); } foreach(stringCciteminchcc) {message. Cc. ADD (Ccitem); } message. Subject=subject; Message. Subjectencoding=Encoding.UTF8; Message. Body=body; Message. Bodyencoding=Encoding.UTF8; Message. Isbodyhtml=true; Message. Priority=Mailpriority.high; Stream Stream=NULL; Attachment Data=NULL; Try { if(Attachment! =NULL&& attachment. Length >0) {Stream=NewMemoryStream (attachment); Data=NewAttachment (Stream, AttachmentName, System.Net.Mime.MediaTypeNames.Application.Octet); Message. Attachments.Add (data); } client. Send (message); } finally { if(NULL!=stream) {stream. Close (); } } }
Three or three ways to send
There are three ways to send mail:
①. Client. Deliverymethod = System.Net.Mail.SmtpDeliveryMethod.Network;
Send mail directly from a remote SMTP server
②. Client. Deliverymethod = System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis;
Send mail through the SMTP service of the native IIS server (what is the next configuration SMTP server in research?). )
③. Client. Deliverymethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
Send the message to the local specified directory, and then send it to the destination by other means (such as via FTP)
Iv. Summary
Only after the practice of paw printing, there is nothing good to summarize.
Respect the original, reprint please indicate from: http://www.cnblogs.com/fsjohnhuang/p/3848355.html ^_^ Fat Boy John