재우니의 블로그

AWS SES 에서 첨부파일을 발송하기 위해 MineKit 를 활용하였습니다.

 

https://www.nuget.org/packages/MimeKit/2.15.1/ReportAbuse

 

NuGet Gallery | Report Package MimeKit 2.15.1

Please provide a detailed description of the problem. If you are reporting copyright infringement, please describe the copyrighted material with particularity and provide us with information about your copyright (i.e. title of copyrighted work, URL where t

www.nuget.org

 

 

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");
            }

        }
    }
}

 

 


 

참고 사이트 

 

https://www.minatcoding.com/blog/tech-tips/tech-tip-send-emails-with-file-attachments-from-a-net-core-app-using-aws-ses

 

Minat Coding - Tech Tip: Send Emails with File Attachments from a .Net Core App using AWS SES

For one of our projects, we built a .Net Core app which sends emails with attachments. SendGrid was originally used as the transactional email service provider to deliver the emails. To integrate with SendGrid, we decided to go with the SMTP relay approach

www.minatcoding.com

 

 

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");
            }

        }
    }
}