Skip to content

Commit

Permalink
Merge branch 'cesargamboa-patch-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Harrison committed Jun 30, 2020
2 parents e90c9d9 + 9275f9d commit 27be177
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions docs/use-cases/attachments.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,62 @@ 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: '[email protected]',
from: '[email protected]',
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: '[email protected]',
from: '[email protected]',
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
}
});
```

0 comments on commit 27be177

Please sign in to comment.