EasyNotice强大易用的消息通知组件
这是一个基于.NET开源的消息通知组件,它包含了邮件通知、钉钉、飞书、企业微信通知,可以帮助我们更容易地发送程序异常通知!
Package Name | Version | Downloads |
---|---|---|
EasyNotice.Core | ||
EasyNotice.Dingtalk | ||
EasyNotice.Email | ||
EasyNotice.Feishu | ||
EasyNotice.Weixin |
- 支持[邮件]、[钉钉]、[飞书]、[企业微信]方式发送
- 支持@指定人员
- 支持自定义发送间隔,避免同样的异常频繁通知
- 傻瓜式配置,开箱即用
- SMTP邮箱
- 钉钉群机器人
- 飞书群机器人
- 企业微信群机器人
项目接入提供了以下发送方式的Demo:邮件通知、钉钉通知、飞书、企业微信通知
邮件通知支持同时发送给多个收件人
Install-Package EasyNotice.Core
Install-Package EasyNotice.Email
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//configuration
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseEmail(option =>
{
option.Host = "smtp.qq.com";//SMTP地址
option.Port = 465;//SMTP端口
option.FromName = "System";//发送人名字(自定义)
option.FromAddress = "12345@qq.com";//发送邮箱
option.Password = "passaword";//秘钥
option.ToAddress = new List<string>()//收件人集合
{
"12345@qq.com"
};
});
});
}
}
[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
private readonly IEmailProvider _mailProvider;
public NoticeController(IEmailProvider provider)
{
_mailProvider = provider;
}
[HttpGet]
public async Task SendMail([FromQuery] string str)
{
await _mailProvider.SendAsync(str, new Exception(str));
}
}
Install-Package EasyNotice.Core
Install-Package EasyNotice.Dingtalk
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//configuration
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseDingTalk(option =>
{
option.WebHook = "https://oapi.dingtalk.com/robot/send?access_token=xxxxx";//通知地址
option.Secret = "secret";//签名校验
});
});
}
}
[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
private readonly IDingtalkProvider _dingtalkProvider;
public NoticeController(IDingtalkProvider dingtalkProvider)
{
_dingtalkProvider = dingtalkProvider;
}
[HttpGet]
public async Task SendDingTalk([FromQuery] string str)
{
await _dingtalkProvider.SendAsync(str, new Exception(str));
}
}
Install-Package EasyNotice.Core
Install-Package EasyNotice.Feishu
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//configuration
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseFeishu(option =>
{
option.WebHook = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxx";//通知地址
option.Secret = "secret";//签名校验
});
});
}
}
[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
private readonly IFeishuProvider _feishuProvider;
public NoticeController(IFeishuProvider feishuProvider)
{
_feishuProvider = feishuProvider;
}
[HttpGet]
public async Task SendFeishu([FromQuery] string str)
{
await _feishuProvider.SendAsync(str, new Exception(str));
}
}
Install-Package EasyNotice.Core
Install-Package EasyNotice.Weixin
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//configuration
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseWeixin(option =>
{
option.WebHook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx";//通知地址
});
});
}
}
[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
private readonly IWeixinProvider _weixinProvider;
public NoticeController(IWeixinProvider weixinProvider)
{
_weixinProvider = weixinProvider;
}
[HttpGet]
public async Task SendWexin([FromQuery] string str)
{
await _weixinProvider.SendAsync(str, new Exception(str));
}
}