Skip to content

Commit

Permalink
feat: add smtp from name and address
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Sep 13, 2019
1 parent ed63575 commit a825824
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/transports/smtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const nodemailer = require('nodemailer');
*/
exports.defaults = {
//default mail sender if non provided during send
from: getString('SMTP_FROM'),
from: getString('SMTP_FROM_ADDRESS') || getString('SMTP_FROM'),

//default smtp port to connect
port: getNumber('SMTP_PORT', 567),
Expand Down Expand Up @@ -113,7 +113,7 @@ exports.toObject = function toObject() {
* @version 0.1.0
* @private
*/
exports.init = function (options) {
exports.init = function(options) {
//initialize transport if not exist
if (!exports.transport) {
//merge options
Expand All @@ -138,7 +138,7 @@ exports.init = function (options) {
* @version 0.1.0
* @private
*/
exports._send = function (message, done) {
exports._send = function(message, done) {
//ensure transport is initialized
exports.init();

Expand All @@ -157,12 +157,16 @@ exports._send = function (message, done) {
//convert message to nodemailer email payload
let email = message.toObject();

// ensure from
email.from = email.sender || getString('SMTP_FROM');

// allow reply to
email.replyTo = email.replyTo || email.sender;

// ensure from
// TODO add from details into message
email.from = {
name: getString('SMTP_FROM_NAME'),
address: getString('SMTP_FROM_ADDRESS') || getString('SMTP_FROM'),
};

// set mail html body
if (message.isHtml()) {
email.html = email.body;
Expand Down Expand Up @@ -190,10 +194,11 @@ exports._send = function (message, done) {
* @version 0.1.0
* @public
*/
exports.send = function (message, done) {
exports.send = function(message, done) {
//ensure email sender
message.sender = message.sender || getString('SMTP_FROM');
message.sender =
message.sender || getString('SMTP_FROM_ADDRESS') || getString('SMTP_FROM');

//perform actual smtp sending
exports._send(message, done);
};
};

0 comments on commit a825824

Please sign in to comment.