-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sends out email
- Loading branch information
Showing
6 changed files
with
2,124 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"settings": { | ||
"react": { | ||
"pragma": "React", | ||
"version": "16.12.0" | ||
} | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "airbnb", | ||
"parserOptions": { | ||
"ecmaVersion": 2019, | ||
"sourceType": "module" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,55 @@ | ||
# email-service | ||
Email service for node clients to send emails via sendgrid | ||
# Email service | ||
Email service for node clients to send emails via sendgrid and mailcatcher | ||
|
||
## Getting Started | ||
|
||
### Installation | ||
|
||
Add this line in package.json `"@kudosinc/email-service": "git+https://[email protected]/KudosInc/email-service.git#v1.0.0"` and run `npm install`. | ||
|
||
### Setting up for mailcatcher | ||
|
||
Following environment varialbes need to be set to send mail via mailcatcher. | ||
|
||
Assuming you already have mailcatcher running locally via docker on the port `1025` and the service name is mailcatcher, set these environment variables | ||
|
||
``` | ||
EMAIL_CLIENT=mailcatcher | ||
SMTP_HOST=mailcatcher | ||
SMTP_PORT=1025 | ||
``` | ||
### Setting up for sendgrid | ||
|
||
To send emails via sendgrid, a template should be created in the sendgrid app, as this service sends email only using the template id. | ||
|
||
Set the following environment variables to configure email service to send emails via sengrid | ||
|
||
``` | ||
EMAIL_CLIENT=sendgrid | ||
SENDGRID_API_KEY=your_key | ||
``` | ||
|
||
#### Creating templates | ||
|
||
To send emails via sendgrid, we need templates created in the sendgrid, and we use the template_id as the sent parameter. The email templates can be cretead in the [sendgrid app](https://mc.sendgrid.com/dynamic-templates) | ||
|
||
### Send Emails | ||
|
||
To send emails look at the example below. | ||
|
||
```javascript | ||
const emailService = require('@kudosinc/email-service'); | ||
|
||
await emailService.sendMail({ | ||
html: 'valid html', //optional, will be respected only in mailcatcher | ||
to: [{ email: '[email protected]', name: 'test test' }], | ||
from: { email: '[email protected]', name: 'sender sender' }, | ||
params: { name: 'sender', company: 'Kudos Inc' }, // required for sendgrid, optional for mailcatcher | ||
templateId: 'template-id', // required for sendgrid to work | ||
subject: 'Subject of the email', | ||
}); | ||
|
||
``` | ||
|
||
**Note:** | ||
If the `html` value is not set when using mailcatcher, it'll concatenate all parameters as a list, and display them as html. The mailcatcher option will not fetch the template html from sendgrid, so the display will not be the same. |
Oops, something went wrong.