Today, the following C # e-mail code, mainly refer to others, the original: http://www.cnblogs.com/xuchi/archive/2011/12/15/2288663.html
1 /// <summary>2 ///Send mail3 /// </summary>4 /// <param name= "SMTP" >Outgoing Server</param>5 /// <param name= "pwd" >Sender Password</param>6 /// <param name= "SendMail" >Sender Mailbox</param>7 /// <param name= "Recipientmail" >Recipient Mailbox</param>8 /// <param name= "Sendusername" >Sender's name</param>9 /// <param name= "Recipientusername" >Recipient's name</param>Ten /// <param name= "Subject" >Message Subject</param> One /// <param name= "Body" >Message Content</param> A /// <param name= "CC" >cc Person</param> - /// <returns>whether the send was successful</returns> - Public Static stringSendMail (stringSmtpstringPwdstringSendMail,stringRecipientmail,stringSendusername,stringRecipientusername,stringSubject,stringBody,string[] CC) the { - Try - { -SmtpClient client =NewSmtpClient (SMTP);//Initializing the server + -Client. useDefaultCredentials =false; +Client. Credentials =NewNetworkCredential (SendMail, PWD);//Sender's account, password AClient. Deliverymethod = Smtpdeliverymethod.network;//Specify how outgoing messages are processed at -MailAddress Addressfrom =NewMailAddress (SendMail, sendusername);//Sender address, name -MailAddress Addressto =NewMailAddress (Recipientmail, recipientusername);//recipient address, name - - //Attachment att= New Attachment (""); //Accessories - inMailMessage message =NewMailMessage (Addressfrom, Addressto);//Sending - //looping through cc people to foreach(varIteminchCC) + { - message. Cc. ADD (item); the } * $Message. Sender =NewMailAddress (SendMail);//Sender AddressPanax NotoginsengMessage. Subject = Subject;//Theme -Message. BODY = body;//content theMessage. bodyencoding = Encoding.UTF8;//Coding +Message. isbodyhtml =true;//is HTML format A the client. Send (message); + return "true"; - } $ Catch(Exception ex) $ { - return(ex. Message); - } the}
C # Send mail