Skip to content

Commit

Permalink
Send email (#1)
Browse files Browse the repository at this point in the history
* sends out email
  • Loading branch information
Talal Arshad authored Mar 26, 2020
2 parents 19686f0 + a665214 commit ea0d496
Show file tree
Hide file tree
Showing 6 changed files with 2,124 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.json
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"
}
}
57 changes: 55 additions & 2 deletions README.md
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.
Loading

0 comments on commit ea0d496

Please sign in to comment.