-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99ff8ff
commit 7d13d9e
Showing
7 changed files
with
113 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ SPARKPOST_API_KEY= | |
SPARKPOST_FROM_EMAIL= | ||
MAILGUN_API_KEY= | ||
MAILGUN_DOMAIN= | ||
SES_KEY= | ||
SES_SECRET= |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,54 @@ | ||
'use strict' | ||
|
||
/* | ||
* adonis-mail | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
const nodemailer = require('nodemailer') | ||
|
||
class SesDriver { | ||
/** | ||
* This method is called by mail manager automatically | ||
* and passes the config object | ||
* | ||
* @method setConfig | ||
* | ||
* @param {Object} config | ||
*/ | ||
setConfig (config) { | ||
this.transporter = nodemailer.createTransport({ | ||
SES: new (require('aws-sdk')).SES(config) | ||
}) | ||
} | ||
|
||
/** | ||
* Send a message via message object | ||
* | ||
* @method send | ||
* @async | ||
* | ||
* @param {Object} message | ||
* | ||
* @return {Object} | ||
* | ||
* @throws {Error} If promise rejects | ||
*/ | ||
send (message) { | ||
return new Promise((resolve, reject) => { | ||
this.transporter.sendMail(message, (error, result) => { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
resolve(result) | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = SesDriver |
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,41 @@ | ||
'use strict' | ||
|
||
/* | ||
* adonis-mail | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
require('dotenv').load() | ||
const test = require('japa') | ||
const { ses: Ses } = require('../src/Mail/Drivers') | ||
|
||
test.group('Ses', () => { | ||
test('send email', async (assert) => { | ||
const config = { | ||
apiVersion: '2010-12-01', | ||
accessKeyId: process.env.SES_KEY, | ||
secretAccessKey: process.env.SES_SECRET, | ||
region: 'us-west-2' | ||
} | ||
|
||
const ses = new Ses() | ||
ses.setConfig(config) | ||
|
||
const response = await ses.send({ | ||
from: [process.env.SMTP_TO_EMAIL], | ||
to: [{ name: 'virk', address: process.env.SMTP_TO_EMAIL }], | ||
subject: 'Plain email', | ||
html: '<h2> Hello </h2>', | ||
attachments: [{ | ||
filename: 'sample.txt', | ||
content: 'Hello world' | ||
}] | ||
}) | ||
|
||
assert.isDefined(response.messageId) | ||
}).timeout(0) | ||
}) |