-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMail.cs
More file actions
34 lines (30 loc) · 1 KB
/
Mail.cs
File metadata and controls
34 lines (30 loc) · 1 KB
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
using MailKit.Net.Smtp;
using MimeKit;
namespace InEngine.Core.IO;
public class Mail
{
public string Host { get; set; }
public int Port { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public void Send(string fromAddress, string toAddress, string subject, string body)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress(fromAddress));
message.To.Add(new MailboxAddress(toAddress));
message.Subject = subject;
message.Body = new TextPart("plain")
{
Text = body
};
using (var client = new SmtpClient())
{
client.Connect(Host, Port, false);
client.AuthenticationMechanisms.Remove("XOAUTH2");
if (!string.IsNullOrWhiteSpace(Username) && !string.IsNullOrWhiteSpace(Password))
client.Authenticate(Username, Password);
client.Send(message);
client.Disconnect(true);
}
}
}