2016-07-19 16 views
1

nodemailerを使用してメールにhtmlテキストを送信できません。nodemailerを使用してhtmlテキストを送信できません

exports.send = function(req, res) { 
console.log(req.query); 
var mailOptions = { 
    to: req.query.email, 
    subject: req.query.sub, 
    text: 'Date of Interview: ' + req.query.dateOfInterview+ 'Time of Interview: ' + req.query.timeOfInterview + '' + req.query.assignedTechnicalPerson + '' + req.query.typeOfInterview + '' + req.query.interviewLocation 
} 
smtpTransport.sendMail(mailOptions, function(error, response) { 
    if (error) { 
     console.log(error); 
     res.end("error"); 
    } else { 
     console.log("Message sent: " + response.message); 
     res.end("sent"); 

    } 
}); 

};

私はそれにhtmlタグを使用して、同じテキストを送信することができますどのように任意の行のスペース ずに連続テキストとしてメールを取得しています私は、HTMLを維持しようとしているとエラー

の多くを取得してしまう私に正しい構文を言ってください。

すべてのヘルプはここで

+0

'email-templates-v2'を使うと、nodemailerで使用できるhtmlテンプレートを定義できます。 –

+0

エラーログも追加できますか?だから問題がどこにあるのか理解できます。 – jerry

答えて

0

がnodemailer最新バージョンで作業コードで認識されます。

var smtpTransport = require('nodemailer-smtp-transport'); 
    var transporter = nodeMailer.createTransport(
     smtpTransport({ 
      service: 'gmail', 
      auth: { 
       user: <Your gmail>, 
       pass: '*****'//ur password 
      } 
     }) 
    ); 
    transporter.sendMail({ 
     from: '[email protected]', 
     to: "[email protected]", 
     subject: 'hello world!', 
     //text:"one" 
     html: '<html><body>Hello World....</body></html>' 
    }, function(error, response) { 
     if (error) { 
      console.log(error); 
     } else { 
      console.log('Message sent'); 
     } 
    }); 

:あなたは Gmailアカウントで "安全性の低いアプリを許可する" を設定する必要がありGmailの

  1. :以下くださいSMTPのアクセス権を与えます。 Click here
  2. 「 Googleアカウントへのアクセスを許可する」でアカウントをロック解除する必要がある場合もあります。
  3. この場合2FAを使用している場合は、 アプリケーション固有のパスワードを作成する必要があります。
関連する問題