2016-03-01 68 views
1

我想通過nodemailer將pdf報告附加到用戶郵件。我在前端使用jQuery。如何在nodemailer中將PDF附加到電子郵件中?

<script> 
$(document).ready(function() { 
    var from, to, subject, text; 
    $("#send_email").click(function() { 
     to = $("#to").val(); 
     subject = $("#subject").val(); 
     text = $("#content").val(); 
     $("#message").text("Sending E-mail..."); 
     $.get("http://localhost:8080/send", {to: to, subject: subject, text: text}, function (data) { 
      if (data == "sent") { 
       $("#message").empty().html("Email is sent " + to + " ."); 
      } 
     }); 
    }); 
}); 
</script> 

而API看起來像這樣。它工作正常。我想知道如何將附件添加到這個動態

app.get('/send', function (req, res) { 
    var mailOptions = { 
     to: req.query.to, 
     subject: req.query.subject, 
     text: req.query.text 
    }; 
    console.log(mailOptions); 
    smtpTransport.sendMail(mailOptions, function (error, response) { 
     if (error) { 
      console.log(error); 
      res.end("error"); 
     } 
     else { 
      console.log("Message sent: " + response.message); 
      res.end("sent"); 
     } 
    }); 
}); 

回答

相關問題