@adamvr/nodemailer-mandrill-transport 中文文档教程
nodemailer-mandrill-transport
Nodemailer 的 Mandrill 传输。
Example
'use strict';
var nodemailer = require('nodemailer');
var mandrillTransport = require('nodemailer-mandrill-transport');
var transport = nodemailer.createTransport(mandrillTransport({
auth: {
apiKey: 'key'
}
}));
transport.sendMail({
from: 'sender@example.com',
to: 'user@example.com',
subject: 'Hello',
html: '<p>How are you?</p>'
}, function(err, info) {
if (err) {
console.error(err);
} else {
console.log(info);
}
});
Using Mandrill API options
可以通过将任何 Messages Send Mandrill API 选项传递到 mandrillOptions
选项。 这些将通过调用此 API 深度合并 运输为您打造。 例如,此传输启用 async
选项 默认情况下。 要禁用此功能,
transport.sendMail({
mandrillOptions: {
async: false
}
}, /* ... */);
Sending Images to Mandrill
要将图像作为附件发送:
transport.sendMail({
mandrillOptions: {
images: [
'type': 'image/png',
'name': 'IMAGECID',
'content': 'ZXhhbXBsZSBmaWxl',
],
}
}, /* ... */);
名称:图像 cid:
在您的 HTML 中引用您的附加图像:
<img src="IMAGECID">
确保为您的图像使用唯一的 cid!
内容:图像的 base64 表示。
var fs = require('fs');
var imgBuff = fs.readFileSync('path/to/file');
imgBuff.toString('base64');
Using Mandrill Templates
使用存储在 Mandrill 上的模板发送电子邮件:
transport.sendMail({
mandrillOptions: {
template_name: 'MANDRILL_TEMPLATE_SLUG'
}
}, /* ... */);
nodemailer-mandrill-transport
A Mandrill transport for Nodemailer.
Example
'use strict';
var nodemailer = require('nodemailer');
var mandrillTransport = require('nodemailer-mandrill-transport');
var transport = nodemailer.createTransport(mandrillTransport({
auth: {
apiKey: 'key'
}
}));
transport.sendMail({
from: 'sender@example.com',
to: 'user@example.com',
subject: 'Hello',
html: '<p>How are you?</p>'
}, function(err, info) {
if (err) {
console.error(err);
} else {
console.log(info);
}
});
Using Mandrill API options
It is possible to use any Messages Send Mandrill API option by passing it into the mandrillOptions
option. These will be deeply merged over the API call this transport builds for you. For example, this transport enables the async
option by default. To disable this,
transport.sendMail({
mandrillOptions: {
async: false
}
}, /* ... */);
Sending Images to Mandrill
To send images as attachments:
transport.sendMail({
mandrillOptions: {
images: [
'type': 'image/png',
'name': 'IMAGECID',
'content': 'ZXhhbXBsZSBmaWxl',
],
}
}, /* ... */);
name: image cid:
Reference your attached image in your HTML:
<img src="IMAGECID">
Make sure to use unique cids for your images!
content: a base64 representation of your image.
var fs = require('fs');
var imgBuff = fs.readFileSync('path/to/file');
imgBuff.toString('base64');
Using Mandrill Templates
To send email using templates stored on Mandrill:
transport.sendMail({
mandrillOptions: {
template_name: 'MANDRILL_TEMPLATE_SLUG'
}
}, /* ... */);