-
Notifications
You must be signed in to change notification settings - Fork 6
/
Plugin.cs
49 lines (41 loc) · 1.43 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using SiteServer.Plugin;
using SS.Mail.Core;
namespace SS.Mail
{
public class Plugin : SiteServer.Plugin.PluginBase
{
public const string PluginId = "SS.Mail";
internal static ConfigInfo GetConfigInfo()
{
return Context.ConfigApi.GetConfig<ConfigInfo>(PluginId, 0) ?? new ConfigInfo();
}
public override void Startup(IService service)
{
service
.AddSystemMenu(() => new Menu
{
Text = "邮件发送设置",
Href = "pages/mail/settings.html"
});
}
public bool IsReady
{
get
{
var config = GetConfigInfo();
return config.IsEnabled && !string.IsNullOrEmpty(config.Address) && !string.IsNullOrEmpty(config.Password);
}
}
public bool Send(string address, string displayName, string title, string body, out string errorMessage)
{
var config = GetConfigInfo();
errorMessage = string.Empty;
var isSuccess = MailManager.Send(config, address, displayName, title, body, out errorMessage);
if (!isSuccess && string.IsNullOrEmpty(errorMessage))
{
errorMessage = "后台邮件发送功能暂时无法使用,请联系管理员或稍后再试";
}
return isSuccess;
}
}
}