Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add more use cases for adding attachments #858

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions use-cases/attachments.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,60 @@ const msg = {
],
};
```
Reading and converting a local PDF file.
```js
import fs from 'fs';

fs.readFile(('Document.pdf'), (err, data) => {
if (err) {
// do something with the error
}
if (data) {
const msg = {
to: 'recipient@test.org',
from: 'sender@test.org',
subject: 'Attachment',
html: '<p>Here’s an attachment for you!</p>',
attachments: [
{
content: data.toString('base64'),
filename: 'some-attachment.pdf',
type: 'application/pdf',
disposition: 'attachment',
contentId: 'mytext',
},
],
};
}
});
```

If you are using a PDF URL:
```js
import request from 'request';

request(fileURl, { encoding: null }, (err, res, body) => {
if (err) { return err; }
if (body) {
const textBuffered = Buffer.from(body);

const msg = {
to: 'recipient@test.org',
from: 'sender@test.org',
subject: 'Attachment',
html: '<p>Here’s an attachment for you!</p>',
attachments: [
{
content: textBuffered.toString('base64'),
filename: 'some-attachment.pdf',
type: 'application/pdf',
disposition: 'attachment',
contentId: 'mytext',
},
],
};
// send msg here
}
});
```