NodeJS를 사용하여 Amazon SES를 통해 여러 파일이 있는 Zip 첨부 파일로 이메일 보내기
파일 시스템 또는 원격 파일의 파일과 같은 다른 소스를 압축할 수도 있습니다.
Buffer로 압축하기 위해 AdmZip로 변환하기만 하면 됩니다.다음 NodeJS 라이브러리를 사용합니다.
추신: 이 전체 작업은 메모리 내에서 수행됩니다. 대용량 파일에는 사용하면 안 됩니다. 이 경우
Stream를 사용해야 합니다.다음은 코드입니다.
const NodeMailer = require("nodemailer");
const AdmZip = require("adm-zip");
const createSampleZip = () => {
const zip = new AdmZip();
zip.addFile("file1.txt", Buffer.from("content of file 1"));
zip.addFile("file2.txt", Buffer.from("content of file 2"));
return zip.toBuffer();
};
const sendEmail = () => {
var sender = NodeMailer.createTransport({
host: "email-smtp.eu-central-1.amazonaws.com",
port: 587,
secure: false, // upgrade later with STARTTLS
auth: {
user: "<<ses-smtp-username>>",
pass: "<<ses-smtp-password>>",
},
});
var mail = {
from: "[email protected]",
to: "[email protected]",
subject: "test email with attachment",
text: "mail body text with attachment",
html: "<h1>mail body in html with attachment</h1>",
// More options regarding attachment here: https://nodemailer.com/message/attachments/
attachments: [
{
filename: "zipfile.zip",
content: createSampleZip(),
},
],
};
console.log("starting to send email");
sender.sendMail(mail, function (error, info) {
if (error) {
console.log(error);
} else {
console.log("Email sent successfully: " + info.response);
}
});
};
sendEmail();
Reference
이 문제에 관하여(NodeJS를 사용하여 Amazon SES를 통해 여러 파일이 있는 Zip 첨부 파일로 이메일 보내기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/amunim/send-email-with-zip-attachment-having-multiple-files-through-amazon-ses-using-nodejs-1p3h텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)