-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail.js
More file actions
44 lines (38 loc) · 1.26 KB
/
Copy pathmail.js
File metadata and controls
44 lines (38 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var request = require("request");
var lineReader = require('line-reader');
var fs = require('fs');
var contents = fs.readFileSync('content.html', 'utf8');
var attachmentBase64 = fs.readFileSync('attachment.txt', 'utf8');
var i = 0;
lineReader.eachLine('emails.txt', function(line, last) {
var options = { method: 'POST',
url: 'https://api.sendgrid.com/v3/mail/send',
headers:
{ 'content-type': 'application/json',
authorization: 'Bearer <<API KEY>>' },
body:
{ personalizations:
[ { to:
[ { email: line,
name: '' } ],
cc:
[ { email: '[email protected]',
name: 'Example Name' } ],
subject: 'Example Subject Line' } ],
from: { email: '[email protected]', name: 'Example Name' },
reply_to: { email: '[email protected]', name: 'Example name' },
content: [ { type: 'text/html', value: contents } ],
attachments:
[ { content: attachmentBase64,
filename: 'filename.extension',
type: 'application/pdf' } ] },
json: true };
module.exports.mailfunc = request(options, function (error, response, body) {
if (error) throw new Error(error);
i = i + 1;
console.log(i + '. ' + line);
});
if (last) {
return false; // stop reading
}
});