ASP.NET中怎么实现邮件发送功能-创新互联
这期内容当中小编将会给大家带来有关ASP.NET中怎么实现邮件发送功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
成都创新互联专注于企业全网整合营销推广、网站重做改版、丹凤网站定制设计、自适应品牌网站建设、H5页面制作、成都商城网站开发、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为丹凤等各大城市提供网站开发制作服务。SMTP邮件发送:
using MailKit.Net.Smtp; using MailKit.Security; using MimeKit; using System.Threading.Tasks; namespace ConsoleApp1 { public class MailHelper { public static void Send(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("tianwei blogs", "mail@hantianwei.cn")); emailMessage.To.Add(new MailboxAddress("mail", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart("plain") { Text = message }; using (var client = new SmtpClient()) { client.Connect("smtp.hantianwei.cn", 465, true); client.Authenticate("mail@hantianwei.cn", "******"); client.Send(emailMessage); client.Disconnect(true); } } public static async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("tianwei blogs", "mail@hantianwei.cn")); emailMessage.To.Add(new MailboxAddress("mail", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart("plain") { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.hantianwei.cn", 25, SecureSocketOptions.None).ConfigureAwait(false); await client.AuthenticateAsync("mail@hantianwei.cn", "******"); await client.SendAsync(emailMessage).ConfigureAwait(false); await client.DisconnectAsync(true).ConfigureAwait(false); } } } }
上述就是小编为大家分享的ASP.NET中怎么实现邮件发送功能了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。
分享文章:ASP.NET中怎么实现邮件发送功能-创新互联
文章地址:http://scyanting.com/article/dodesp.html