Skip to content

Instantly share code, notes, and snippets.

@brianbancroft
Last active November 10, 2018 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianbancroft/489506b31178ecf9fe7ddf165d61cbf8 to your computer and use it in GitHub Desktop.
Save brianbancroft/489506b31178ecf9fe7ddf165d61cbf8 to your computer and use it in GitHub Desktop.
Basic Nodemailer App
EMAIL_ADDRESS=''
EMAIL_PASSWORD=''
require("dotenv").config();
const nodemailer = require("nodemailer");
// This content would likely be populated through API Params
const message = "test test test 123 123 123";
const sender = {
address: "",
name: ""
};
nodemailer.createTestAccount((err, account) => {
let transporter = nodemailer.createTransport({
service: "Gmail",
auth: {
user: process.env.EMAIL_ADDRESS,
pass: process.env.EMAIL_PASSWORD
}
});
let mailOptions = {
from: `"Brian Bancroft (ME)" <${process.env.EMAIL_ADDRESS}>`,
to: `"Brian Bancroft (ME)" <${process.env.EMAIL_ADDRESS}>`,
cc: `"${sender.name}" <${sender.email}>`,
subject: "Form Response for bancroft.io",
html: `
<span>Okay, so we got another mail now..\n\n\n
${message}</span>`
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
});
});
{
"name": "basic-email-sender",
"version": "1.0.0",
"description": "A simple email sending service using gmail",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "Brian Bancroft (hello@brianbancroft.ca)",
"license": "ISC",
"dependencies": {
"dotenv": "^6.1.0",
"nodemailer": "^4.6.8"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment