btcpayserver/BTCPayServer/Services/Mails/EmailSettings.cs

83 lines
1.8 KiB
C#
Raw Normal View History

2017-09-27 14:18:09 +09:00
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Net.Mail;
namespace BTCPayServer.Services.Mails
{
public class EmailSettings
{
[Display(Name = "SMTP Server")]
public string Server
{
get; set;
}
2017-09-27 14:18:09 +09:00
public int? Port
{
get; set;
}
2017-09-27 14:18:09 +09:00
public string Login
{
get; set;
}
2020-06-28 17:55:27 +09:00
public string Password
{
get; set;
}
[Display(Name = "Sender's display name")]
public string FromDisplay
{
get; set;
}
[EmailAddress]
[Display(Name = "Sender's email address")]
public string From
{
get; set;
}
2017-09-27 14:18:09 +09:00
2019-03-03 16:47:37 -06:00
[Display(Name = "Enable SSL")]
public bool EnableSSL
{
get; set;
}
2017-09-27 14:18:09 +09:00
2018-05-05 01:42:42 +09:00
public bool IsComplete()
{
try
{
2020-01-12 15:32:26 +09:00
using var smtp = CreateSmtpClient();
2018-05-05 01:42:42 +09:00
return true;
}
catch { }
return false;
}
public MailMessage CreateMailMessage(MailAddress to, string subject, string message)
{
return new MailMessage(
from: new MailAddress(From, FromDisplay),
to: to)
{
Subject = subject,
Body = message
};
}
public SmtpClient CreateSmtpClient()
{
SmtpClient client = new SmtpClient(Server, Port.Value);
2018-05-22 18:05:44 +09:00
client.EnableSsl = EnableSSL;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(Login, Password);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Timeout = 10000;
return client;
}
}
2017-09-27 14:18:09 +09:00
}