-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (58 loc) · 1.79 KB
/
index.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
const nodemailer = require("nodemailer");
const dns = require("dns");
const mailList = ["[email protected]","[email protected]"]
const fromMail = "[email protected]"
const fromName = "kuwa-network✔"
const sendMail = {
"title": "notic test message📢",
"text": "test mail",
"html": "This email wassent to check the smtp port.<br>このメールはsmtpポートのチェック用に送信されたものです。"
}
async function getMX(domain){
return new Promise((resolve) => {
dns.resolveMx(domain, (err,address)=>{
if(err){
resolve(null)
}else{
resolve(address)
}
});
})
}
(async ()=>{
mailList.forEach( async (mail) =>{
const mx = await getMX(mail.split("@")[1])//mx取得
if(!mx){
console.log("error domain")
return
}
// console.log(mx)
const mxPriority = mx.map((data) => data.priority).sort((a, b)=>{
return a - b
})//mxの優先順位高い順に優先リストに入れる
for(const priority of mxPriority){//優先リスト高い順にfor
try{
const address = mx.find(data => data.priority == priority).exchange
console.log(address)
let transporter = nodemailer.createTransport({
host: address,
port: 25,
// logger: true,
// debug: true,
// secure: true,
});
transporter.sendMail({
from: `"${fromName}" <${fromMail}`,
to: mail,
subject: sendMail.title,
text: sendMail.text,
html: sendMail.html,
});
console.log(`Message sent to ${mail}`);
break
}catch (err){
console.log
}
}
})
})()