email.js 915 B

123456789101112131415161718192021222324252627282930313233
  1. const nodemailer = require("nodemailer");
  2. const config = require('./config')
  3. const main = async (userEmail, usermessage) => {
  4. try {
  5. // let captcha = Math.floor(Math.random() * 9000) + 1000
  6. let transporter = nodemailer.createTransport({
  7. host: config.host,
  8. port: config.port,
  9. auth: {
  10. user: config.user, // 用户名
  11. pass: config.pass // 密码
  12. },
  13. tls: {
  14. rejectUnauthorized: false
  15. }
  16. });
  17. let info = await transporter.sendMail({
  18. from: '"1473" <postmaster@mail.1473.cn>', // sender address
  19. to: `${userEmail}`, // list of receivers
  20. subject: "邮件", // Subject line
  21. html: `<h2>${usermessage}</h2>`
  22. });
  23. return 'success'
  24. } catch (error) {
  25. return 'err'
  26. }
  27. }
  28. module.exports = main