我们已经测试了很多方法,我很好奇我们是否需要向接口 EmailOptions
interface EmailOptions<T = any> {
/**
* The template name
*/
template?: string;
/**
* Nodemailer Message <Nodemailer.com/message/>
*
* Overrides what is given for constructor
*/
message?: Mail.Options;
/**
* The Template Variables
*/
locals?: T;
///do we need attachments?:someObj; here?
}
这是图像文件的绝对路径。 包/api/image/header.jpg
这是邮件程序文件的绝对路径。 包/api/helper/mailer.js
This is the html.pug
img(src= 'header.jpg' alt='header' style='width:100%; height:auto;')
This is the email method
function sendSurveyEmail(application) {
email.send({
template: 'survey',
message: {
from: 'Person <person@email.org>',
to: 'Other@person.io'
},
locals: {
name: application.thisName,
patientName: application.thatName,
appUrl: process.env.APP_URL,
},
attachments: [{
filename: 'header.jpg',
path: '.public/image/header.jpg',
cid: 'header.jpg'
}]
}).catch((err) => console.log(err))
.then(() => console.log('email has been sent!'));
}