summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElmer Thomas <elmer@thinkingserious.com>2016-09-06 16:07:55 -0700
committerElmer Thomas <elmer@thinkingserious.com>2016-09-06 16:07:55 -0700
commit8e39d349c05a394279e9b7f76f58db4a69de34b3 (patch)
treef20424046830dc92e0b1a9b0fcdd8404bb49976a
parent69ed562e4c46e216dcb79f040a3577101508547d (diff)
downloadsendgrid-nodejs-8e39d349c05a394279e9b7f76f58db4a69de34b3.zip
sendgrid-nodejs-8e39d349c05a394279e9b7f76f58db4a69de34b3.tar.gz
sendgrid-nodejs-8e39d349c05a394279e9b7f76f58db4a69de34b3.tar.bz2
Added attachments example
-rw-r--r--USE_CASES.md47
1 files changed, 47 insertions, 0 deletions
diff --git a/USE_CASES.md b/USE_CASES.md
index f0d52d7..10f27ca 100644
--- a/USE_CASES.md
+++ b/USE_CASES.md
@@ -2,8 +2,55 @@ This documentation provides examples for specific use cases. Please [open an iss
# Table of Contents
+* [Attachments](#attachments)
* [Transactional Templates](#transactional_templates)
+<a name="attachments"></a>
+# Attachments
+
+Here is an example of attaching a text file to your email, assuming that text file `my_file.txt` is located in the same directory.
+
+```javascript
+var helper = require('sendgrid').mail;
+var sg = require('sendgrid')(process.env.SENDGRID_API_KEY);
+var fs = require('fs');
+
+var mail = new helper.Mail();
+var email = new helper.Email('test@example.com', 'Example User');
+mail.setFrom(email);
+
+mail.setSubject('Hello World from the SendGrid Node.js Library');
+
+var personalization = new helper.Personalization();
+email = new helper.Email('test@example.com', 'Example User');
+personalization.addTo(email);
+mail.addPersonalization(personalization);
+
+var content = new helper.Content('text/html', '<html><body>some text here</body></html>')
+mail.addContent(content);
+
+var attachment = new helper.Attachment();
+var file = fs.readFileSync('my_file.txt');
+var base64File = new Buffer(file).toString('base64');
+attachment.setContent(base64File);
+attachment.setType('application/text');
+attachment.setFilename('my_file.txt');
+attachment.setDisposition('attachment');
+mail.addAttachment(attachment);
+
+var request = sg.emptyRequest({
+ method: 'POST',
+ path: '/v3/mail/send',
+ body: mail.toJSON(),
+});
+
+sg.API(request, function(err, response) {
+ console.log(response.statusCode);
+ console.log(response.body);
+ console.log(response.headers);
+});
+```
+
<a name="transactional_templates"></a>
# Transactional Templates