gmail-nodemailer-transport
v3.0.2
Published
Gmail API and Nodemailer v4+. The plugin uses send scope only
Downloads
196
Maintainers
Readme
gmail-nodemailer-transport
Intro
The custom transport plugin that allows to send email using Nodemailer via Gmail
Why?
With the help of the Gmail API it is possible to use the send scope and Nodemailer v4+. The plugin is very small, optimized and written in TypeScript
Support the project
If you like to use this module please click the star button - it is very motivating.
Quick Start
Install gmail-nodemailer-transport using npm:
$ npm install gmail-nodemailer-transport --save
Documentation
Nodemailer common fields are supported and replyTo
Examples
send the simple email by the access token
'use strict';
const nodemailer = require('nodemailer');
const GmailTransport = require('gmail-nodemailer-transport');
let transporter = nodemailer.createTransport(new GmailTransport({
userId: '[email protected]',
auth: {
accessToken: 'ya29.Glv5BvE5y-access-token'
}
}));
transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
replyTo: '[email protected]',
subject: 'Gmail Transport',
text: 'This is text content'
}).then((info) => {
console.log('SUCCESS');
}).catch((error) => {
console.log('Something is wrong');
});
send the simple email, if it's failed to refresh the access token
'use strict';
const nodemailer = require('nodemailer');
const GmailTransport = require('gmail-nodemailer-transport');
let transporter = nodemailer.createTransport(new GmailTransport({
userId: '[email protected]',
auth: {
clientId: 'clien-id.apps.googleusercontent.com',
clientSecret: 'clint-secret',
refreshToken: '1/EAATBaMn-refresh-token',
accessToken: 'ya29.Glv5BvE5y-access-token'
}
}));
transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
replyTo: '[email protected]',
subject: 'Gmail Transport',
text: 'This is text content'
}).then((info) => {
console.log('SUCCESS');
}).catch((error) => {
console.log('Something is wrong');
});
send an attachment and embed it to the content
'use strict';
const nodemailer = require('nodemailer');
const GmailTransport = require('gmail-nodemailer-transport');
let transporter = nodemailer.createTransport(new GmailTransport({
userId: '[email protected]',
auth: {
accessToken: 'ya29.Glv5BvE5y-access-token'
}
}));
transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
replyTo: '[email protected]',
subject: 'Gmail Transport',
html: '<!DOCTYPE html><html><body><img src="cid:attachment" alt="attachment"></body></html>',
attachments: [{
content: '/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAA...', // base64 content
cid: 'attachment',
contentType: 'image/jpeg',
filename: 'attachment.jpg',
encoding: 'base64'
}]
}).then((info) => {
console.log('SUCCESS');
}).catch((error) => {
console.log('Something is wrong');
});