前言
在日常軟件開(kāi)發(fā)中,電子郵件處理是一個(gè)不可或缺的功能,無(wú)論是用戶(hù)注冊(cè)驗(yàn)證、通知推送還是日常的業(yè)務(wù)溝通,都離不開(kāi)電子郵件的支持。今天大姚給大家分享2款.NET開(kāi)源、高效、強(qiáng)大的.NET電子郵件處理庫(kù),這些庫(kù)不僅簡(jiǎn)化了電子郵件的發(fā)送、接收和管理工作,還提供了豐富的功能和靈活的配置選項(xiàng),以滿足各種復(fù)雜的業(yè)務(wù)需求。
MailKit
MailKit是一個(gè)跨平臺(tái)、開(kāi)源(MIT License)、免費(fèi)的.NET郵件處理庫(kù),提供強(qiáng)大的 API,用于發(fā)送、接收和處理電子郵件,并且它還提供了對(duì)SMTP、POP3和IMAP協(xié)議的全面支持。
開(kāi)源地址:https://github.com/jstedfast/MailKit
發(fā)送電子郵件簡(jiǎn)單操作:
using System;
using MailKit.Net.Smtp;
using MailKit;
using MimeKit;
namespace TestClient {
class Program
{
public static void Main (string[] args)
{
var message = new MimeMessage ();
message.From.Add (new MailboxAddress ("Joey Tribbiani", "joey@friends.com"));
message.To.Add (new MailboxAddress ("Mrs. Chanandler Bong", "chandler@friends.com"));
message.Subject = "How you doin'?";
message.Body = new TextPart ("plain") {
Text = @"Hey Chandler,
I just wanted to let you know that Monica and I were going to go play some paintball, you in?
-- Joey"
};
using (var client = new SmtpClient ()) {
client.Connect ("smtp.friends.com", 587, false);
// Note: only needed if the SMTP server requires authentication
client.Authenticate ("joey", "password");
client.Send (message);
client.Disconnect (true);
}
}
}
}
FluentEmail
FluentEmail 是一個(gè)用于 .NET 和 .NET Core 的電子郵件發(fā)送庫(kù),它提供了簡(jiǎn)單易用的 API 來(lái)發(fā)送電子郵件。該項(xiàng)目支持使用 Razor 模板來(lái)創(chuàng)建電子郵件內(nèi)容,并可以通過(guò) SendGrid、MailGun、SMTP 等多種方式進(jìn)行發(fā)送。
開(kāi)源地址:https://github.com/lukencode/FluentEmail
發(fā)送電子郵件簡(jiǎn)單操作:
var email = await Email
.From("john@email.com")
.To("bob@email.com", "bob")
.Subject("hows it going bob")
.Body("yo bob, long time no see!")
.SendAsync();
// Using Razor templating package (or set using AddRazorRenderer in services)
Email.DefaultRenderer = new RazorRenderer();
var template = "Dear @Model.Name, You are totally @Model.Compliment.";
var email = Email
.From("bob@hotmail.com")
.To("somedude@gmail.com")
.Subject("woo nuget")
.UsingTemplate(template, new { Name = "Luke", Compliment = "Awesome" });
轉(zhuǎn)自https://www.cnblogs.com/Can-daydayup/p/18344124
該文章在 2024/8/8 9:02:25 編輯過(guò)