You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.9 KiB
1.9 KiB
LINGYUN.Abp.Notifications.Emailing
通知系统的邮件发送模块,提供了通过邮件发送通知的功能。
功能特性
- 邮件通知发送
- 邮件模板支持
- 支持HTML格式邮件
- 支持多收件人
- 支持抄送和密送
模块引用
[DependsOn(typeof(AbpNotificationsEmailingModule))]
public class YouProjectModule : AbpModule
{
// other
}
配置项
{
"Notifications": {
"Emailing": {
"Templates": {
"Default": {
"Template": "DefaultTemplate",
"Culture": "zh-Hans"
}
}
}
}
}
基本用法
- 配置邮件设置
Configure<AbpEmailingOptions>(options =>
{
options.DefaultFromAddress = "noreply@example.com";
options.DefaultFromDisplayName = "Notification System";
});
- 发送邮件通知
public class YourNotificationHandler : INotificationHandler
{
private readonly IEmailSender _emailSender;
public YourNotificationHandler(IEmailSender emailSender)
{
_emailSender = emailSender;
}
public async Task HandleAsync(NotificationInfo notification)
{
await _emailSender.SendAsync(
to: notification.UserEmail,
subject: notification.Title,
body: notification.Content,
isBodyHtml: true
);
}
}
- 使用邮件模板
public async Task SendWithTemplateAsync()
{
var template = await _templateRenderer.RenderAsync(
"DefaultTemplate",
new {
Title = "通知标题",
Content = "通知内容"
}
);
await _emailSender.SendAsync(
to: "user@example.com",
subject: "通知",
body: template,
isBodyHtml: true
);
}