-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Reldens - v4.0.0 - Mailer fix WIP.
- Loading branch information
1 parent
0822a34
commit 4e60e1d
Showing
9 changed files
with
316 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* | ||
* Reldens - NodemailerFactory | ||
* | ||
*/ | ||
|
||
const Nodemailer = require('nodemailer'); | ||
const { Logger, sc } = require('@reldens/utils'); | ||
|
||
class NodemailerFactory | ||
{ | ||
|
||
setup(mailer) | ||
{ | ||
if(!mailer){ | ||
Logger.error('Mailer not found on NodemailerFactory.'); | ||
return false; | ||
} | ||
if(!mailer.pass){ | ||
Logger.error('Required mailer password not found on NodemailerFactory.'); | ||
return false; | ||
} | ||
if(!mailer.host || !mailer.port || !mailer.user || !mailer.pass){ | ||
Logger.error('NodemailerFactory required configuration not specified.', { | ||
host: mailer.host, | ||
port: mailer.port, | ||
user: mailer.user, | ||
pass: mailer.pass | ||
}); | ||
return false; | ||
} | ||
try { | ||
return Nodemailer.createTransport({ | ||
host: mailer.host, | ||
port: mailer.port, | ||
secure: Boolean(sc.get(mailer, 'secure', true)), | ||
auth: { | ||
// @NOTE: for example, this could be "user" and "password" values from https://forwardemail.net. | ||
user: mailer.user, | ||
pass: mailer.pass | ||
} | ||
}); | ||
} catch (error) { | ||
Logger.error('Nodemailer transport error.', error); | ||
return false; | ||
} | ||
} | ||
|
||
async sendEmail(props) | ||
{ | ||
if(!props.transporter){ | ||
Logger.error('Transporter not found on Nodemailer.'); | ||
return false; | ||
} | ||
if(!props.mailOptions){ | ||
Logger.error('Mail options not found on Nodemailer.'); | ||
return false; | ||
} | ||
try { | ||
return await props.transporter.sendMail(props.mailOptions); | ||
} catch (error) { | ||
Logger.error('Nodemailer sendMail error.', error, props.mailOptions); | ||
return false; | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports.NodemailerFactory = NodemailerFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* | ||
* Reldens - SendGridFactory | ||
* | ||
*/ | ||
|
||
const SendGridMail = require('@sendgrid/mail'); | ||
const { Logger } = require('@reldens/utils'); | ||
|
||
class SendGridFactory | ||
{ | ||
|
||
async setup(mailer) | ||
{ | ||
if(!mailer){ | ||
Logger.error('Mailer not found on SendGridFactory.'); | ||
return false; | ||
} | ||
if(!mailer.pass){ | ||
Logger.error('Required mailer password not found on SendGridFactory.'); | ||
return false; | ||
} | ||
try { | ||
SendGridMail.setApiKey(mailer.pass); | ||
return SendGridMail; | ||
} catch (error) { | ||
Logger.error('SendGrid transport error.', error); | ||
return false; | ||
} | ||
} | ||
|
||
async sendEmail(props) | ||
{ | ||
if(!props.transporter){ | ||
Logger.error('Transporter not found on SendGrid.'); | ||
return false; | ||
} | ||
if(!props.mailOptions){ | ||
Logger.error('Mail options not found on SendGrid.'); | ||
return false; | ||
} | ||
try { | ||
return await props.transporter.send(props.mailOptions); | ||
} catch (error) { | ||
Logger.error('SendGrid sendMail error.', error, props.mailOptions); | ||
return false; | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports.SendGridFactory = SendGridFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.