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
|
|
|
|
{
|
2019-08-07 21:31:08 +02:00
|
|
|
[Display(Name = "SMTP Server")]
|
2017-10-27 17:53:04 +09:00
|
|
|
public string Server
|
|
|
|
{
|
|
|
|
get; set;
|
|
|
|
}
|
2017-09-27 14:18:09 +09:00
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
public int? Port
|
|
|
|
{
|
|
|
|
get; set;
|
|
|
|
}
|
2017-09-27 14:18:09 +09:00
|
|
|
|
2019-05-01 05:17:25 +02:00
|
|
|
public string Login
|
2017-10-27 17:53:04 +09:00
|
|
|
{
|
|
|
|
get; set;
|
|
|
|
}
|
2020-06-28 17:55:27 +09:00
|
|
|
|
2019-05-01 05:17:25 +02:00
|
|
|
public string Password
|
2017-10-27 17:53:04 +09:00
|
|
|
{
|
|
|
|
get; set;
|
|
|
|
}
|
2019-07-14 22:45:14 +09:00
|
|
|
|
|
|
|
[Display(Name = "Sender's display name")]
|
|
|
|
public string FromDisplay
|
|
|
|
{
|
|
|
|
get; set;
|
|
|
|
}
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
[EmailAddress]
|
2019-07-14 22:45:14 +09:00
|
|
|
[Display(Name = "Sender's email address")]
|
2017-10-27 17:53:04 +09:00
|
|
|
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")]
|
2017-10-27 17:53:04 +09:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-07-14 22:45:14 +09:00
|
|
|
public MailMessage CreateMailMessage(MailAddress to, string subject, string message)
|
|
|
|
{
|
|
|
|
return new MailMessage(
|
|
|
|
from: new MailAddress(From, FromDisplay),
|
|
|
|
to: to)
|
|
|
|
{
|
|
|
|
Subject = subject,
|
|
|
|
Body = message
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-10-27 17:53:04 +09:00
|
|
|
public SmtpClient CreateSmtpClient()
|
|
|
|
{
|
|
|
|
SmtpClient client = new SmtpClient(Server, Port.Value);
|
2018-05-22 18:05:44 +09:00
|
|
|
client.EnableSsl = EnableSSL;
|
2017-10-27 17:53:04 +09:00
|
|
|
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
|
|
|
}
|