首页 > 代码库 > 使用C#发送邮件支持 Implicit SSL
使用C#发送邮件支持 Implicit SSL
安装Package:
Install-Package AIM
使用下面的代码发送:
class Mail { private static string mailAddress = "{you email address}"; private static string host = "{your host server}"; private static string userName = "{your user name}"; private static string password = "{your password}"; private static string userTo = "{to address}"; private static void SendEmail(string subject, string message) { //Generate Message var mailMessage = new MimeMailMessage(); mailMessage.From = new MimeMailAddress(mailAddress); mailMessage.To.Add(userTo); mailMessage.Subject = subject; mailMessage.Body = message; //Create Smtp Client var mailer = new MimeMailer(host, 465); mailer.User = userName; mailer.Password = password; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; //Set a delegate function for call back mailer.SendCompleted += compEvent; mailer.SendMailAsync(mailMessage); } //Call back function private static void compEvent(object sender, AsyncCompletedEventArgs e) { if (e.UserState != null) Console.Out.WriteLine(e.UserState.ToString()); Console.Out.WriteLine("is it canceled? " + e.Cancelled); if (e.Error != null) Console.Out.WriteLine("Error : " + e.Error.Message); } }
使用C#发送邮件支持 Implicit SSL
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。