-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathmailTester.js
93 lines (74 loc) · 2.31 KB
/
mailTester.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* eslint no-console: 0 */
'use strict';
const nodemailer = require('nodemailer');
const fs = require('fs');
// read properties
const properties = JSON.parse(fs.readFileSync('properties.json'));
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
// Create a SMTP transporter object
let transporter = nodemailer.createTransport(
{
host: properties.host || 'localhost',
port: properties.smtpPort,
logger: false,
debug: false // include SMTP traffic in the logs
},
{
// default message fields
// sender info
from: 'AHEM Test main! <no-reply@ahem.email>',
headers: {
}
}
);
// Message object
let email = process.argv[2] || 'test@' + properties.allowedDomains[0]
console.log( email);
let recipientAddress = process.argv[2] || '<'+ 'test@' + properties.allowedDomains[0] + '>';
let message = {
// Comma separated list of recipients
to: recipientAddress,
// Subject of the message
subject: 'Welcome to AHEM! ✔',
// plaintext body
text: 'Hello to myself!',
// HTML body
html:
'<p><b>Hello</b> to myself <img src="cid:note@example.com"/></p>' +
'<p><br/><img src="cid:ahem-tester@mydomain.com"/></p>',
// An array of attachments
attachments: [
// String attachment
{
filename: 'notes.txt',
content: 'Some notes about this e-mail',
},
// Binary Buffer attachment
{
filename: 'image.png',
content: Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC',
'base64'
),
cid: 'note@example.com' // should be as unique as possible
},
// File Stream attachment
{
filename: 'ahem-happy.png',
path: __dirname + '/client/assets/images/ahem-fumbled.png',
cid: 'ahem-tester@mydomain.com' // should be as unique as possible
}
]
};
transporter.sendMail(message, (error, info) => {
if (error) {
console.log('Error occurred');
console.log(error.message);
return process.exit(1);
}
console.log('Message sent successfully!');
// only needed when using pooled connections
transporter.close();
});