static string accountName = "发件人邮箱"; static string password = "发件人邮箱密码"; static string smtpServer = "smtp.qiye.aliyun.com"; static int smtpPort = 80; static string displayName = "发件人显示"; //static string userState = System.Configuration.ConfigurationManager.AppSettings["mailUserState"]; static public void SendMail(string sendTo, string emailCC, string strsubject, string strbody) { try { Console.WriteLine("发送中…………"); // Command line argument must the the SMTP host. SmtpClient client = new SmtpClient(smtpServer, smtpPort); client.UseDefaultCredentials = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Credentials = new NetworkCredential(accountName, password); // Specify the e-mail sender. // Create a mailing address that includes a UTF8 character // in the display name. MailAddress from = new MailAddress(accountName, displayName, System.Text.Encoding.UTF8); // Set destinations for the e-mail message. MailAddress to = new MailAddress(sendTo); // Specify the message content. MailMessage message = new MailMessage(from, to); if (!string.IsNullOrEmpty(emailCC)) { message.CC.Add(emailCC); } message.Body = strbody; // Include some non-ASCII characters in body and subject. string someArrows = "(请勿回复这封邮件)"; message.Body += Environment.NewLine + someArrows; message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = strsubject; message.SubjectEncoding = System.Text.Encoding.UTF8; message.Priority = MailPriority.High; message.IsBodyHtml = true; client.Send(message); message.Dispose(); client.Dispose(); Console.WriteLine("成功"); } catch (Exception ex) { Console.WriteLine("失败"); Console.WriteLine(ex.InnerException.ToString()); } }