-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
30 lines (28 loc) · 1.03 KB
/
Program.cs
File metadata and controls
30 lines (28 loc) · 1.03 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
using System;
using System.Threading.Tasks;
using MailKit.Net.Smtp;
using MailKit.Security;
using MimeKit;
namespace EP210_MimeKitSendEmailToSmtp4Dev
{
class Program
{
static async Task Main(string[] args)
{
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress("System", "system@test.com"));
emailMessage.To.Add(new MailboxAddress("Dave Paquette", "dave@dave.com"));
emailMessage.Subject = "This is a test";
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = "<h1>Important message</h1><p>This is from the system</p>";
emailMessage.Body = bodyBuilder.ToMessageBody();
using (var client = new SmtpClient())
{
var secureSocketOptions = SecureSocketOptions.None;
client.Connect("localhost", 25, secureSocketOptions);
await client.SendAsync(emailMessage);
client.Disconnect(true);
}
}
}
}