-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattachment_resource
33 lines (23 loc) · 1.42 KB
/
attachment_resource
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
var message = new MimeMessage();
message.To.Add(new MailboxAddress("[email protected]", "[email protected]"));//收件人
message.From.Add(new MailboxAddress("xxxx", "[email protected]"));//发件人
message.Subject = "邮件测试主题2";
var builder = new BodyBuilder();
var image = builder.LinkedResources.Add(path);
image.ContentId = MimeUtils.GenerateMessageId();
builder.TextBody = string.Format(@"[cid:{0}] Hey AnLong", image.ContentId);
builder.HtmlBody = string.Format(@"<p>Hey anlong</p><p>Will you be my +1</p><center><img src=""cid:{0}""></center>", image.ContentId);
// We may also want to attach a calendar event for Monica's party...
builder.Attachments.Add(@"C:\Users\Joey\Documents\party.ics");
message.Body = builder.ToMessageBody();
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("smtp.163.com", 465, true);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate("[email protected]", "123456");
client.Send(message);
client.Disconnect(true);
}