-
Notifications
You must be signed in to change notification settings - Fork 13
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 self signed certificate for smtp transport option #40
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ try { | |
// Do not set AWS_SDK_LOAD_CONFIG if aws config file is missing. | ||
} | ||
|
||
module.exports = async function sendEmail(filename, url, sender, recipient, transport, smtphost, smtpport, smtpsecure, smtpusername, smtppassword, subject, note, emailbody) { | ||
module.exports = async function sendEmail(filename, url, sender, recipient, transport, smtphost, smtpport, smtpsecure, smtpusername, smtppassword, subject, note, emailbody, selfsignedcerts) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might start to make sense to turn this into an object-reference, with an interface. Naming might be hard, though I could make more sense and less brain-power out of arguments named This would also mean that further config changes (new options) do not cause change on this method (or at least this method signature |
||
if (transport !== undefined && (transport === 'smtp' || ses !== undefined) && sender !== undefined && recipient !== undefined) { | ||
spinner.start('Sending email...'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like making this module to two different things : 1. format/send email. 2. control UI/UX. I think the only question in splitting this up would be if there is expected some "on-the-fly" UX while the email-sending process is ongoing... In our modern computing environment, there shouldn't be a timing issue... emails never take > 10sec so send.. or else they fail immediately. |
||
} else { | ||
|
@@ -41,7 +41,7 @@ module.exports = async function sendEmail(filename, url, sender, recipient, tran | |
|
||
let mailOptions = getmailOptions(url, sender, recipient, filename, subject, note, emailbody); | ||
|
||
let transporter = getTransporter(transport, smtphost, smtpport, smtpsecure, smtpusername, smtppassword); | ||
let transporter = getTransporter(transport, smtphost, smtpport, smtpsecure, smtpusername, smtppassword, selfsignedcerts); | ||
|
||
transporter.use("compile", hbs({ | ||
viewEngine: { | ||
|
@@ -54,21 +54,22 @@ module.exports = async function sendEmail(filename, url, sender, recipient, tran | |
|
||
// send email | ||
return new Promise((success, fail) => { | ||
transporter.sendMail(mailOptions, function (err, info) { | ||
if (err) { | ||
spinner.fail('Error sending email' + err); | ||
fail(err); | ||
exit(1); | ||
} else { | ||
spinner.succeed('Email sent successfully'); | ||
deleteTemporaryImage(emailbody); | ||
success(info); | ||
} | ||
}); | ||
transporter.sendMail(mailOptions, function (err, info) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be a lot more clear using a try..catch.. .and if necessary a throw on self-detected error (err value is not null?) |
||
if (err) { | ||
spinner.fail('Error sending email' + err); | ||
fail(err); | ||
exit(1); | ||
} else { | ||
spinner.succeed('Email sent successfully'); | ||
deleteTemporaryImage(emailbody); | ||
success(info); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
const getTransporter = (transport, smtphost, smtpport, smtpsecure, smtpusername, smtppassword, transporter) => { | ||
const getTransporter = (transport, smtphost, smtpport, smtpsecure, smtpusername, smtppassword, selfsignedcerts, transporter) => { | ||
var rejectSelfSignedCerts = selfsignedcerts === 'true' ? false : true; | ||
if (transport === 'ses') { | ||
transporter = nodemailer.createTransport({ | ||
SES: ses | ||
|
@@ -81,7 +82,10 @@ const getTransporter = (transport, smtphost, smtpport, smtpsecure, smtpusername, | |
auth: { | ||
user: smtpusername, | ||
pass: smtppassword, | ||
} | ||
}, | ||
tls: { | ||
rejectUnauthorized: rejectSelfSignedCerts, | ||
}, | ||
}); | ||
} | ||
return transporter; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you try this merge strategy :
I think would both clarify the defaults, and make the fallback assignments a one-liner.