# Region send email
/// <Summary>
/// Send an email through an attachment
/// </Summary>
/// <Param name = "emailfrom"> sender's email address </param>
/// <Param name = "Files"> image address </param>
/// <Param name = "emailfromname"> sender name </param>
/// <Param name = "zsrlist"> recipient set </param>
/// <Param name = "csrlist"> CC set </param>
/// <Param name = "arrfilepath"> attachment path </param>
/// <Param name = "mailsubject"> topic </param>
/// <Param name = "mailbody"> body content </param>
/// <Returns> </returns>
Public static bool sendemail (string emailfrom, string [] files, string emailfromname, ilist <CSR> zsrlist, ilist <CSR> csrlist, arraylist arrfilepath, string mailsubject, string mailbody)
{
Mailmessage email = new mailmessage ();
Try
{
Mailaddress emailfrom = new mailaddress (emailfrom, emailfromname); // create a sender email address object
Email. From = emailfrom; // specify the sender
Email. CC. Add (emailfrom); // send the sender as a CC
For (INT I = 0; I <zsrlist. Count; I ++) // cyclically Add the master mail address object
{
Mailaddress zsraddr = new mailaddress (zsrlist [I]. Email, zsrlist [I]. Name );
Email. to. Add (zsraddr );
}
For (INT I = 0; I <csrlist. Count; I ++) // cyclically Add the CC recipient email address object
{
Mailaddress csraddr = new mailaddress (csrlist [I]. Email, csrlist [I]. Name );
Email. CC. Add (csraddr );
}}
Catch
{
Return false;
} Email. isbodyhtml = true;
Email. bodyencoding = system. Text. encoding. utf8;
Email. Body + = mailbody;
For (INT I = 0; I <files. length; I ++)
{
System. net. Mail. Attachment attachment = new system. net. Mail. Attachment (files [I]);
Email. attachments. Add (Attachment );
Email. Body + = " ";
} Email. Priority = mailpriority. High;
// Email Subject
Email. Subject = mailsubject;
Email. subjectencoding = encoding. getencoding (936); // email attachment
For (INT I = 0; I <arrfilepath. Count; I ++)
{
String file = arrfilepath [I]. tostring (); // attachment path
Attachment DATA = new attachment (file, system. net. Mime. mediatypenames. application. octet );
// Add time stamp information for the file.
System. net. Mime. contentdisposition disposition = data. contentdisposition;
Disposition. creationdate = system. Io. file. getcreationtime (File );
Disposition. modificationdate = system. Io. file. getlastwritetime (File );
Disposition. readdate = system. Io. file. getlastaccesstime (File );
// Add the file attachment to this e-mail message.
Email. attachments. Add (data );
}
Smtpclient client = new smtpclient ("172.30.1.13 ");
Client. usedefacrecredentials = false;
Client. Credentials = new system. net. networkcredential ("Shoa", "shnetweb.1234 ");
Client. deliverymethod = smtpdeliverymethod. Network; try
{
Client. Send (email );
}
Catch (smtpfailedrecipientsexception ex)
{
For (INT I = 0; I <ex. innerexceptions. length; I ++)
{
Smtpstatuscode status = ex. innerexceptions [I]. statuscode;
If (status = smtpstatuscode. mailboxbusy | status = smtpstatuscode. mailboxunavailable)
{
// Response. Write ("Delivery failed-retrying in 5 seconds .");
System. Threading. thread. Sleep (5000 );
Client. Send (email );
}
}
}
Catch (exception ex)
{
Return false;
}
Finally
{
For (INT I = 0; I <email. attachments. Count; I ++) // release Excel Resources
{
Email. attachments [I]. Dispose ();
}
}
Return true;
}
# Endregion