forked from maildev/maildev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-sendmail.js
More file actions
60 lines (53 loc) · 2.26 KB
/
example-sendmail.js
File metadata and controls
60 lines (53 loc) · 2.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"use strict";
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const nodemailer = require("nodemailer");
async function main() {
const transporter = nodemailer.createTransport({
host: "0.0.0.0",
port: 8025,
auth: { type: "login", user: "username", pass: "password" },
});
// send mail with defined transport object
const info = await transporter.sendMail({
from: '"Fred Foo 👻" <[email protected]>', // sender address
replyTo: "[email protected]", // reply-to address
subject: "Hello ✔ - Special chars: <>&\"' and emojis 🎉🚀", // Subject line with special characters
text: "Hello world?\n\nThis is a plain text body with special characters: <>&\"'\nAnd a second line with unicode: 日本語テスト\nAnd a URL: https://example.com?foo=bar&baz=qux", // plain text body
html: `
<html>
<body>
<h1>Hello world? 🌍</h1>
<p>This is an <b>HTML</b> body with <i>special characters</i>: <>&"'</p>
<p>Unicode test: 日本語テスト</p>
<a href="https://example.com?foo=bar&baz=qux">Click here</a>
<img src="https://placehold.co/600x400" alt="Test image" />
<script>alert('xss')</script> <!-- XSS attempt for validation testing -->
</body>
</html>
`, // html body
attachments: [
{
filename: "test.txt",
content: "This is a test attachment with special chars: <>&\"'",
},
{
filename: "hello.html",
content: "<h1>Hello</h1>",
contentType: "text/html",
},
],
headers: {
"X-Custom-Header": "custom-value",
"X-Priority": "1",
},
});
console.log("Message sent: %s", info.messageId);
// Message sent: <[email protected]>
// Preview only available when sending through an Ethereal account
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
main().catch(console.error);