Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. var helper = require('sendgrid').mail;
  2. var sg = require('sendgrid')("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");
  3.  
  4. var mail = new helper.Mail();
  5. var email = new helper.Email('cankoathanasios@gmail.com', 'Athanasios Canko');
  6. mail.setFrom(email);
  7.  
  8. mail.setSubject('QR Code Attachment (PNG)');
  9.  
  10. var content = new helper.Content('text/plain', 'Hello, this is a PNG version of the QR code screenshot.')
  11. mail.addContent(content);
  12.  
  13. var attachment = new helper.Attachment();
  14. var file = fs.readFileSync(__dirname + "/screenshot.png");
  15. var base64File = new Buffer(file).toString('base64');
  16. attachment.setContent(base64File);
  17. attachment.setFilename('screenshot.png');
  18. attachment.setDisposition('attachment');
  19. mail.addAttachment(attachment);
  20.  
  21. var object = [
  22. {email: "xxxxxxxxxxxxxxx@hotmail.com", name: "xxxxxx"},
  23. {email: "xxxxxxxxxxxxxxx@gmail.com", name: "xxxxxx"}
  24. ];
  25.  
  26. for (var i = 0; i < object.length; i += 1) {
  27. var personalization = new helper.Personalization();
  28. email = new helper.Email(object[i].email, object[i].name);
  29. personalization.addTo(email);
  30. mail.addPersonalization(personalization);
  31.  
  32. var request = sg.emptyRequest({
  33. method: 'POST',
  34. path: '/v3/mail/send',
  35. body: mail.toJSON(),
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement