using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Net.Mail; using System.Text; using System.Threading.Tasks; namespace GeoSigma.SigmaDrawerUtil { public class MailMsgHelp { private static string mail2 = "gch_ling@163.com"; /// /// 向指定邮箱发送信息 /// /// 接收者邮箱 /// 邮件主题 /// 邮件内容 public static void SendInfoToMailbox( string mailContent) { // SendMailbox:发送信息的邮箱 // SMIPServiceCode:邮箱smtp服务密码,确保邮箱已经开启了SMTP服务,开启后会给出一串编码就是smtp服务密码,后台填入编码 // Host:邮箱服务器类型,QQ邮箱:smtp.qq.com // Port:邮箱服务器端口SendMailbox, receivingMailbox, subject, mailContent try { string subject = "Drawer"; MailMessage msg = new MailMessage(); msg.From = new MailAddress("chinasofter@gmail.com"); msg.To.Add(mail2); msg.Subject = subject; msg.Body = mailContent; msg.IsBodyHtml = false; SmtpClient client = new SmtpClient("smtp.gmail.com", 465); //client.UseDefaultCredentials = false; System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("chinasofter@gmail.com", "gch_ling@163.com"); client.Credentials = basicAuthenticationInfo; client.EnableSsl = true; //client.Host = "localhost"; client.SendCompleted += (object sender, AsyncCompletedEventArgs e) => { System.Diagnostics.Trace.WriteLine(sender.ToString()); }; client.Send(msg); //string userState = "test message1"; // client.SendAsync(msg, userState); msg.Dispose(); } finally { } } } }