Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. net. mail;
Using system. configuration;
Using system. collections;
Using system. Data. sqlclient;
Public partial class _ default: system. Web. UI. Page
{
Public String mailcontent;
Protected void page_load (Object sender, eventargs E)
{
}
Public void send ()
{
Mailmessage mail = new mailmessage ();
Try
{
// Set the mail title
Mail. Subject = "youzai WebService Report ";
Mail. subjectencoding = system. Text. encoding. utf8;
// Set the sender of the email
String sendemail = configurationmanager. receivetask[ "sendemail"]. tostring ();
Mailaddress addressfrom = new mailaddress (sendemail, "uzai", system. Text. encoding. utf8); // mail sender
Mail. From = addressfrom;
/* This is written here because it may be sent to multiple contacts. Each address is separated by a comma (,).
*/
List <string> mailaddress = new list <string> ();
Foreach (string address in mailaddress)
{
If (address! = String. Empty)
{
Mail. to. Add (New mailaddress (address, address, system. Text. encoding. utf8 ));
}
}
// Set the email content
Mail. Body = mailcontent;
// Set the mail format
Mail. bodyencoding = system. Text. encoding. utf8;
// Mail. isbodyhtml = true;
// Set the mail sending level
Mail. Priority = mailpriority. normal;
// Send a notification
Mail. deliverynotificationoptions = deliverynotificationoptions. onsuccess;
Smtpclient client = new smtpclient ();
// Set the name of the host used for SMTP transaction, and enter the IP address.
Client. Host = "smtp.gmail.com ";
Client. Port = 25;
Client. Timeout = 9999;
Client. usedefacrecredentials = true;
Client. enablessl = true;
// Email login name and password
String emaillogname = configurationmanager. receivettings ["emaillogname"]. tostring ();
String emaillogpwd = configurationmanager. receivettings ["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 email address for sending an exception
Sendbackup ();
}
Finally
{
Mail. Dispose ();
}
}
Public void sendbackup ()
{
Mailmessage mail = new mailmessage ();
Try
{
// Set the mail title
Mail. Subject = "youzai WebService Report ";
Mail. subjectencoding = system. Text. encoding. utf8;
// Set the sender of the email
String sendemail = system. configuration. configurationmanager. receivetask[ "sendemail"]. tostring ();
Mailaddress addressfrom = new mailaddress (sendemail, "uzai", system. Text. encoding. utf8); // mail sender
Mail. From = addressfrom;
/* This is written here because it may be sent to multiple contacts. Each address is separated by a comma (,).
*/
List <string> mailaddress = new list <string> ();
Foreach (string address in mailaddress)
{
If (address! = String. Empty)
{
Mail. to. Add (New mailaddress (address, address, system. Text. encoding. utf8 ));
}
}
// Set the email content
Mail. Body = mailcontent;
// Set the mail format
Mail. bodyencoding = system. Text. encoding. utf8;
// Mail. isbodyhtml = true;
// Set the mail sending level
Mail. Priority = mailpriority. normal;
// Send a notification
Mail. deliverynotificationoptions = deliverynotificationoptions. onsuccess;
Smtpclient client = new smtpclient ();
// Set the name of the host used for SMTP transaction, and enter the IP address.
Client. Host = "smtp.gmail.com ";
Client. Port = 25;
Client. Timeout = 9999;
Client. usedefacrecredentials = true;
Client. enablessl = true;
// Email login name and password
String emaillogname = configurationmanager. receivettings ["emaillogname"]. tostring ();
String emaillogpwd = configurationmanager. receivettings ["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 email address for sending an exception
Send ();
}
Finally
{
Mail. Dispose ();
}
}
}