SendRawEmailAWS SDKOR와 함께 사용 CLI - AWS SDK코드 예제

AWS 문서 AWS SDK SDK 예제 GitHub 리포지토리에 더 많은 예제가 있습니다.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

SendRawEmailAWS SDKOR와 함께 사용 CLI

다음 코드 예제는 SendRawEmail의 사용 방법을 보여 줍니다.

CLI
AWS CLI

Amazon을 사용하여 원본 이메일을 보내려면 SES

다음 예시에서는 send-raw-email 명령을 사용하여 TXT 첨부 파일이 포함된 이메일을 보냅니다.

aws ses send-raw-email --raw-message file://message.json

출력:

{ "MessageId": "EXAMPLEf3f73d99b-c63fb06f-d263-41f8-a0fb-d0dc67d56c07-000000" }

원시 메시지는 현재 message.json 디렉터리에 이름이 지정된 파일에 저장된 JSON 데이터 구조입니다. 이는 다음을 포함합니다.

{ "Data": "From: sender@example.com\nTo: recipient@example.com\nSubject: Test email sent using the AWS CLI (contains an attachment)\nMIME-Version: 1.0\nContent-type: Multipart/Mixed; boundary=\"NextPart\"\n\n--NextPart\nContent-Type: text/plain\n\nThis is the message body.\n\n--NextPart\nContent-Type: text/plain;\nContent-Disposition: attachment; filename=\"attachment.txt\"\n\nThis is the text in the attachment.\n\n--NextPart--" }

보시다시피 “데이터”는 attachment.txt 첨부 파일을 포함하여 원시 이메일 내용 전체가 MIME 형식으로 포함된 하나의 긴 문자열입니다.

sender@example.com 및 recipient@example.com을 사용하려는 주소로 바꿉니다. 발신자의 이메일 주소는 SES Amazon에서 확인해야 한다는 점에 유의하십시오. Amazon에 대한 프로덕션 액세스 권한을 부여받기 전까지는 수신자의 이메일 주소도 확인해야 합니다. 단SES, 수신자가 Amazon SES 메일박스 시뮬레이터가 아니라면 말입니다. 확인에 대한 자세한 내용은 Amazon Simple Email Service 개발자 안내서의 SES Amazon의 이메일 주소 및 도메인 확인을 참조하십시오.

출력의 메시지 ID는 호출이 send-raw-email 성공했음을 나타냅니다.

이메일을 받지 못한 경우 정크 박스를 확인해 보세요.

원시 이메일을 보내는 방법에 대한 자세한 내용은 Amazon SES API Simple Email Service 개발자 안내서의 Amazon을 사용한 원시 이메일 전송을 참조하십시오.

  • 자세한 API 내용은 AWS CLI 명령 SendRawEmail참조를 참조하십시오.

JavaScript
SDK JavaScript (v3) 에 대한
참고

더 많은 정보가 있습니다. GitHub AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

nodemailer를 사용하여 첨부 파일이 있는 이메일을 보냅니다.

import sesClientModule from "@aws-sdk/client-ses"; /** * nodemailer wraps the SES SDK and calls SendRawEmail. Use this for more advanced * functionality like adding attachments to your email. * * https://nodemailer.com/transports/ses/ */ import nodemailer from "nodemailer"; /** * @param {string} from An Amazon SES verified email address. * @param {*} to An Amazon SES verified email address. */ export const sendEmailWithAttachments = ( from = "from@example.com", to = "to@example.com", ) => { const ses = new sesClientModule.SESClient({}); const transporter = nodemailer.createTransport({ SES: { ses, aws: sesClientModule }, }); return new Promise((resolve, reject) => { transporter.sendMail( { from, to, subject: "Hello World", text: "Greetings from Amazon SES!", attachments: [{ content: "Hello World!", filename: "hello.txt" }], }, (err, info) => { if (err) { reject(err); } else { resolve(info); } }, ); }); };