Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into cesargamboa-patch-1
  • Loading branch information
Sam Harrison committed Jun 30, 2020
2 parents e90c9d9 + dfed045 commit 9275f9d
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions docs/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: '[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 9275f9d

Please sign in to comment.