2017-08-08 38 views
0

第一次使用節點並使用電子郵件配置。我下載了這個application from here,它工作(使用mustache.js爲電子郵件生成模板),但測試電子郵件以我的Gmail垃圾郵件結束。通過nodemailer從我的服務器發送的電子郵件通過垃圾郵件發送:(未知發件人)

from: via vps1234.inmotionhosting.com 
to: [email protected] 
date: Tue, Aug 8, 2017 at 5:30 PM 
subject: Thanks! and review your experience 
mailed-by: vps1234.inmotionhosting.com 
security: Standard encryption (TLS) Learn more 

-

var nodemailer = require('nodemailer'); 
let transporter = nodemailer.createTransport({ 
     service: ' ', 
     secure: false, 
     port: 25, 
     auth: { 
      user: '[email protected]', 
      pass: 'password1234' 
     }, 
     tls: { 
     rejectUnauthorized: false, 
    } 
}), 


EmailTemplate = require('email-templates').EmailTemplate, 
path = require('path'), 
Promise = require('bluebird'); 

let users = [ 
    { 
     name: 'John', 
     note: 'I found your purse', 
     email: '[email protected]', 
    } 
]; 



function sendEmail (obj) { 
    return transporter.sendMail(obj); 
} 

function loadTemplate (templateName, contexts) { 
    let template = new EmailTemplate(path.join(__dirname, 'templates', templateName)); 
    return Promise.all(contexts.map((context) => { 
     return new Promise((resolve, reject) => { 
      template.render(context, (err, result) => { 
       if (err) reject(err); 
       else resolve({ 
        email: result, 
        context, 
       }); 
      }); 
     }); 
    })); 
} 

loadTemplate('welcome', users).then((results) => { 
    return Promise.all(results.map((result) => { 
     sendEmail({ 
      to: result.context.email, 
      from: 'Me :)', 
      subject: result.email.subject, 
      html: result.email.html, 
      text: result.email.text, 
     }); 
    })); 
}).then(() => { 
    console.log('Yay!'); 
}); 

這是Nodemailer樣板,這也是我測試了我的服務器上,而它的工作正常,和電子郵件沒有得到標記:

var nodemailer = require('nodemailer'); 

let transporter = nodemailer.createTransport({ 
    service: ' ', 
    secure: false, 
    port: 25, 
    auth:{ 
     user: '[email protected]', 
     pass: 'password1234' 
    }, 
    tls: { 
     rejectUnauthorized: false, 
    } 
}); 


let helperOptions = { 
    from: '<[email protected]>', 
    to: '[email protected]', 
}; 

transporter.sendMail(helperOptions, (error, info) =>{ 
    if(error){return alert(error);} 
    console.log("sent" . info); 
}) 
+0

一般來說,從您自己的Web服務器發送電子郵件是一個壞主意,你看過Amazon SES或Mailgun嗎?這些服務將提供SMTP端點來發送電子郵件(並且它們完成所有繁重的工作,而不會被標記爲垃圾郵件) – jye265

回答

1

消息被標記爲垃圾郵件並不是產生它的代碼的功能,而是一些其他事情的功能,例如:

  • 實際內容(文字,鏈接等)

的第一個問題來了域名就是你有玩的東西。 MailMonitor等服務可幫助您調整內容,以瞭解Gmail和其他人如何處理它。措辭,HTML與純文本,鏈接與無,等等都起作用。

就域而言,您需要設置SPF(發件人策略框架)和DKIM條目,以基本驗證您的域是否爲正確的發件人。 「未知發件人」很可能是缺少SPF記錄。

對於SPF,這裏是article。 對於DKIM這裏的another

請注意,我剛剛爲此搜索 - 他們看起來像很好的文章,但我相信還有其他很好的來源。

它的要點是你要在你的DNS中創建幾個TXT條目。有些工具如SPF發生器可以幫助你解決這個問題。這聽起來並不複雜。

一旦完成,你可能仍然在垃圾郵件,但它肯定會有所幫助。您可以嘗試使用服務,例如Amazon SESSendGrid,這些服務可能會比您當前的SMTP服務器提供更好的發送「有效性」。