Skip to content

Commit

Permalink
docs: Improve the mail package's README to handle the async send() (#877
Browse files Browse the repository at this point in the history
)

I included the missing bits to handle the asynchronous `send()` call
including both ES6 and ES8 approaches which closes #870.
  • Loading branch information
Berkmann18 authored Feb 13, 2020
1 parent de73e14 commit 8162318
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/mail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,18 @@ const msg = {
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg)
.then((res) => //resolved )
.catch((error) => //rejected )
//ES6
sgMail
.send(msg)
.then(() => {}, console.error);
//ES8
(async () => {
try {
await sgMail.send(msg);
} catch (err) {
console.error(err.toString());
}
})();
```

After executing the above code, you should have an email in the inbox of the recipient. You can check the status of your email [in the UI](https://app.sendgrid.com/email_activity?). Alternatively, we can post events to a URL of your choice using our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html). This gives you data about the events that occur as Twilio SendGrid processes your email.
Expand Down

0 comments on commit 8162318

Please sign in to comment.