Public void Send () {MailMessage mail = new MailMessage (); try {// set the mail title. subject = "youzai WebService Report"; mail. subjectEncoding = System. text. encoding. UTF8; // set the sender string SendEmail = ConfigurationManager. deleetask[ "SendEmail"]. toString (); MailAddress Addressfrom = new MailAddress (SendEmail, "uzai", System. text. encoding. UTF8); // The mail sender's mail. from = Addressfrom;/* this is written here because it may be sent to multiple contacts. Each address is separated by a comma. */List
MailAddress = new List
(); Foreach (string address in mailAddress) {if (address! = String. empty) {mail. to. add (new MailAddress (address, address, System. text. encoding. UTF8) ;}/// set the mail content to mail. body = mailContent; // set the mail format. bodyEncoding = System. text. encoding. UTF8; // mail. isBodyHtml = true; // sets the mail sending level. priority = MailPriority. normal; // send the notification mail. deliveryNotificationOptions = DeliveryNotificationOptions. onSuccess; SmtpClient client = new SmtpClient (); // set the name of the host used for SMTP transaction, and enter the IP address or the client. host = "smtp.gmail.com"; client. port = 25; client. timeout = 9999; client. usedefacrecredentials = true; client. enableSsl = true; // The email login name and password string EmailLogName = ConfigurationManager. appSettings ["EmailLogName"]. toString (); string EmailLogPwd = ConfigurationManager. appSettings ["EmailLogPwd"]. toString (); client. credentials = new System. net. networkCredential (EmailLogName, EmailLogPwd); client. deliveryMethod = SmtpDeliveryMethod. network; // send email client. send (mail);} catch (Exception) {// when the email fails to be sent, use the alternative method to call the alternate mailbox to Send SendBackUp ();} finally {mail. dispose () ;}} public void SendBackUp () {MailMessage mail = new MailMessage (); try {// set the mail title. subject = "youzai WebService Report"; mail. subjectEncoding = System. text. encoding. UTF8; // set the sender string SendEmail = ConfigurationManager. deleetask[ "SendEmail"]. toString (); MailAddress Addressfrom = new MailAddress (SendEmail, "uzai", System. text. encoding. UTF8); // The mail sender's mail. from = Addressfrom;/* this is written here because it may be sent to multiple contacts. Each address is separated by a comma. */List
MailAddress = new List
(); Foreach (string address in mailAddress) {if (address! = String. empty) {mail. to. add (new MailAddress (address, address, System. text. encoding. UTF8) ;}/// set the mail content to mail. body = mailContent; // set the mail format. bodyEncoding = System. text. encoding. UTF8; // mail. isBodyHtml = true; // sets the mail sending level. priority = MailPriority. normal; // send the notification mail. deliveryNotificationOptions = DeliveryNotificationOptions. onSuccess; SmtpClient client = new SmtpClient (); // set the name of the host used for SMTP transaction, and enter the IP address or the client. host = "smtp.gmail.com"; client. port = 25; client. timeout = 9999; client. usedefacrecredentials = true; client. enableSsl = true; // The email login name and password string EmailLogName = ConfigurationManager. appSettings ["EmailLogName"]. toString (); string EmailLogPwd = ConfigurationManager. appSettings ["EmailLogPwd"]. toString (); client. credentials = new System. net. networkCredential (EmailLogName, EmailLogPwd); client. deliveryMethod = SmtpDeliveryMethod. network; // send email client. send (mail);} catch (Exception) {// when the email fails to be sent, use the alternate method to call the alternate mailbox to Send ();} finally {mail. dispose ();}}