Created
May 19, 2016 07:41
-
-
Save johnsonz/c0624569d7636a3003e091a88d5ac98d to your computer and use it in GitHub Desktop.
C#发送邮件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void SendEmail(string from, string subject, string body, string[] to, string[] cc, string[] bcc, string host, int port) | |
{ | |
try | |
{ | |
MailMessage message = new MailMessage(); | |
message.From = new MailAddress(from); | |
if (to.Length > 0) | |
{ | |
foreach (string s in to) | |
{ | |
message.To.Add(new MailAddress(s)); | |
} | |
} | |
if (cc.Length > 0) | |
{ | |
foreach (string s in cc) | |
{ | |
message.CC.Add(new MailAddress(s)); | |
} | |
} | |
message.Subject = subject; | |
message.Body = body; | |
message.IsBodyHtml = false; | |
message.BodyEncoding = System.Text.Encoding.UTF8; | |
SmtpClient smtp = new SmtpClient(); | |
smtp.Host = host; | |
smtp.Port = port; | |
smtp.UseDefaultCredentials = true; | |
smtp.Send(message); | |
WriteLog(1, LogName, "Send Mail Success"); | |
} | |
catch (Exception ex) | |
{ | |
WriteLog(-1, LogName, "Send Mail Failure" + " Message:" + ex.Message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment