[Csharp]
<Span style = "font-size: 14px;" >/// <summary>
/// Send emails synchronously
/// </Summary>
/// <Param name = "fromEmail"> sender's email </param>
/// <Param name = "fromPwd"> sender's email password </param>
/// <Param name = "toEmail"> recipient's email </param>
/// <Param name = "subject"> email title </param>
/// <Param name = "body"> the email is empty. </param>
/// <Param name = "emailType"> mail type </param> smtp.163.com.cn; smtp.qq.com.cn; smtp.126.com.cn; smtp.sina.com.cn
Private void SendEmail (string fromEmail, string fromPwd, string toEmail, string subject, string body, string emailType)
{
MailAddress addrFrom = new MailAddress (fromEmail, fromEmail );
MailAddress addrTo = new MailAddress (toEmail, toEmail );
Attachment att = new Attachment (attFile, MediaTypeNames. Application. Octet );
MailMessage mm = new MailMessage (addrFrom, addrTo );
Mm. BodyEncoding = Encoding. UTF8;
Mm. IsBodyHtml = true;
Mm. Subject = subject;
Mm. Body = body;
If (! String. IsNullOrEmpty (attFile ))
{
ContentDisposition cd = att. ContentDisposition;
Cd. CreationDate = File. GetCreationTime (attFile );
Cd. ModificationDate = File. GetLastWriteTime (attFile );
Cd. ReadDate = File. GetLastAccessTime (attFile );
Mm. Attachments. Add (att); // Add an attachment.
}
NetworkCredential nc = new NetworkCredential (fromEmail, fromPwd );
SmtpClient smtp = new SmtpClient (emailType );
Smtp. usedefacrecredentials = false;
Smtp. Credentials = nc;
Smtp. EnableSsl = false;
Smtp. DeliveryMethod = SmtpDeliveryMethod. Network;
Smtp. Send (mm );
} </Span>