Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mailtrap email #82

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/core-generators/new/get-package-json-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ module.exports = function getPackageJsonData(scope) {
grunt: scope.caviar? GRUNT_DEP_SVR: undefined,
'sails-hook-grunt': scope.caviar? SAILS_HOOK_GRUNT_DEP_SVR: undefined,

'nodemailer': '6.4.16',
},
scripts: {
start:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module.exports = {
var path = require('path');
var url = require('url');
var util = require('util');

var nodemailer = require('nodemailer');

if (!_.startsWith(path.basename(template), 'email-')) {
sails.log.warn(
Expand Down Expand Up @@ -206,6 +206,35 @@ module.exports = {
htmlEmailContents+'\n'+
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-'
);
} else if (sails.config.environment === 'development' && sails.config.custom.mailtrap) {
// Send an email using Mailtrap in development environment

var transport = nodemailer.createTransport(sails.config.custom.mailtrap);

var fromNameString = fromName || sails.config.custom.fromName;
var fromEmailString = from || sails.config.custom.fromEmailAddress;
var message = {
from: fromNameString ? `"${sails.config.custom.fromName}" <${sails.config.custom.fromEmailAddress}>` : fromEmailString,
to: toName ? `"${toName}" <${to}>` : to,
bcc,
subject: inputs.subject,
html: htmlEmailContents,
attachments
}

try {
var info = await transport.sendMail(message);
sails.log.info(
`Message ${info.messageId} was sent via MailTrap in Development`
);
} catch (err) {
sails.log.error(
'Error while trying to send an email with Mailtrap:\n' +
util.inspect({template, templateData, to, toName, subject, from, fromName, layout, ensureAck, bcc, attachments},{depth:null})+'\n',
'Error details:\n'+
util.inspect(err));
}

} else {
// Otherwise, we'll check that all required Mailgun credentials are set up
// and, if so, continue to actually send the email.
Expand Down
23 changes: 23 additions & 0 deletions lib/core-generators/new/templates/config/custom.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ module.exports.custom = {
* *
**************************************************************************/
// sendgridSecret: 'SG.fake.3e0Bn0qSQVnwb1E4qNPz9JZP5vLZYqjh7sn8S93oSHU',

/**************************************************************************
* *
* Email configuration for development *
* *
* Try Mailtrap to send emails an receive in the app inboxes. *
* - Open https://mailtrap.io/inboxes and select your inbox *
* - Click "SMTP Settings" tab *
* - At "Integrations" options select Node.js - Nodemailer *
* - Copy the configuration object and paste it below *
* *
* (https://mailtrap.io/) *
* *
**************************************************************************/
// mailtrap: {
// host: "smtp.mailtrap.io",
// port: 2525,
// auth: {
// user: "212asdasdasda2",
// pass: "b12sa142asda12"
// }
// }

//--------------------------------------------------------------------------
// /\ Configure this to enable support for automated emails.
// || (Important for password recovery, verification, contact form, etc.)
Expand Down