using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Amazon.SimpleEmail;
using Amazon.SimpleEmail.Model;
using MimeKit;
using System;
using System.IO;
using System.Threading.Tasks;
using Amazon;
namespace AwsSesEmailApp
{
internal class Program
{
static async Task Main(string[] args)
{
using (var client = new AmazonSimpleEmailServiceClient("AWS SES 키값",
"AWS SES 비밀키값",
RegionEndpoint.APNortheast2))
{
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = "안녕하세요. 대학내일 심재운 입니다. . Please view the attachment.";
bodyBuilder.TextBody = "안녕하세요. 대학내일 심재운 입니다. . Please view the attachment.";
var path = "D:/sample/AwsSesEmailApp/회의록.txt";
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
bodyBuilder.Attachments.Add("회의록.txt", fileStream);
}
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress("발송자이메일주소", "발송자이메일주소"));
mimeMessage.To.Add(new MailboxAddress("수신자이메일주소", "수신자이메일주소"));
mimeMessage.Subject = "안녕하세요. 대학내일 심재운 입니다. ";
mimeMessage.Body = bodyBuilder.ToMessageBody();
using (var messageStream = new MemoryStream())
{
await mimeMessage.WriteToAsync(messageStream);
var sendRequest = new SendRawEmailRequest { RawMessage = new RawMessage(messageStream) };
var response = await client.SendRawEmailAsync(sendRequest);
}
Console.WriteLine("Email Successfully Sent");
}
}
}
}
using Amazon.SimpleEmail;
using Amazon.SimpleEmail.Model;
using MimeKit;
using System;
using System.IO;
using System.Threading.Tasks;
namespace MinatCoding.AwsSesEmail
{
class Program
{
static async Task Main(string[] args)
{
using (var client = new AmazonSimpleEmailServiceClient("AWS Access Key", "AWS Secret Key"))
{
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = "Hello World. Please view the attachment.";
bodyBuilder.TextBody = "Hello World. Please view the attachment.";
using (FileStream fileStream = new FileStream("File path e.g. C:/pics/my-pic.jpg", FileMode.Open, FileAccess.Read))
{
bodyBuilder.Attachments.Add("Filename.ext e.g pic.jpg", fileStream);
}
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress("From Name", "From email address e.g. no-reply@minatcoding.com"));
mimeMessage.To.Add(new MailboxAddress("Recipient Name", "recipient email address e.g. recipient@minatcoding.com"));
mimeMessage.Subject = "Hello World";
mimeMessage.Body = bodyBuilder.ToMessageBody();
using (var messageStream = new MemoryStream())
{
await mimeMessage.WriteToAsync(messageStream);
var sendRequest = new SendRawEmailRequest { RawMessage = new RawMessage(messageStream) };
var response = await client.SendRawEmailAsync(sendRequest);
}
Console.WriteLine("Email Successfully Sent");
}
}
}
}