本文实例为大家分享了.net发送邮件的实现代码,供大家参考,具体内容如下
关键代码:
需要引用命名空间:
using System.Net.Mail;
using System.Net;
MailMessage mailObj = new MailMessage();
mailObj.From = new MailAddress(mayunqq.com); //发送人邮箱地址
mailObj.To.Add(mahuatengqq.com); //收件人邮箱地址
准备将一些项目迁移到 asp.net core 先从封装类库入手,在遇到邮件发送类时发现在 asp.net core 1.0中并示提供SMTP相关类库,于是网上一搜发现了MailKit
好东西一定要试一下,何况是开源,下面是代码可实现SMTP邮件发送:
using MailKit.Net.Smtp;
using MailKit.Security;
using MimeKit;
using System.Threading.Tasks;
namespace ConsoleApp1
{
p
本文实例讲述了C#实现异步发送邮件的方法。分享给大家供大家参考。具体如下:
下面的代码可以实现异步发送邮件,等邮件发送出去后会自动调用回调函数,这样在发送邮件时就不会卡住程序不动了
MailMessage m = new MailMessage
(itemjb51.net,
rajajb51.net,
This is the subject for the authorized email.,
This is the body of the authorized mail!..