如何解决Nodemailer在失眠中工作,但不在我的网站上
当我通过Insomnia发出请求时,它会起作用并发送电子邮件(请参见图片)。
当我浏览我的网站时,它会返回状态200,但不会发送电子邮件。
禁用了我可以从Google获得的所有安全配置。
从这里https://community.nodemailer.com/using-gmail/
尝试解决此问题的时间少于2小时。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const nodemailer = require('nodemailer');
const smtpTransport = require('nodemailer-smtp-transport');
//const cors = require('cors')({origin: true});
admin.initializeApp();
/*let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',port: 465,secure: true,auth: {
user: 'xxxxxx@gmail.com',pass: 'xxxxx'
}
});*/
let transporter = nodemailer.createTransport(smtpTransport({
host: 'smtp.gmail.com',pass: 'xxxxx'
}
}));
exports.processForm = functions.https.onRequest((req,res) => {
const body = req.body;
const nome = body.nome;
const cpf = body.cpf;
const email = body.email;
const deliveryType = body.deliveryType;
const observacoes = body.observacoes;
const profundidade = body.profundidade;
const telefone = body.telefone;
const cep = body.cep;
const estado = body.estado;
const cidade = body.cidade;
const latitude = body.latitude;
const longitude = body.longitude;
const Now = new Date();
const year = Now.getFullYear();
const month = Now.getMonth().toString().length < 2 ? '0' + Now.getMonth() : Now.getMonth();
const day = Now.getDate().toString().length < 2 ? '0' + Now.getDate() : Now.getDate();
const subject = `${day}/${month}/${year} - Solicitação de análise criada em Poços da Serra!`;
const protocolo = `${year}-${month}-${day}-${Now.getHours()}:${Now.getMinutes()}:${Now.getSeconds()}.${Now.getMilliseconds()}`;
const html = `<h2>Protocolo: ${protocolo}</h2>
<p>Solicitação de análise criada com sucesso!</p>
<p>Nome: ${nome}<br>
CPF: ${cpf}<br>
Telefone: ${telefone}<br>
Email: ${email}<br><br>
Formato de entrega: ${deliveryType}<br>
CEP: ${cep}<br>
Estado: ${estado}<br>
Cidade: ${cidade}<br>
Coordenadas: ${latitude},${longitude}<br>
Profundidade: ${profundidade}m<br>
Observações: ${observacoes}<br></p>
<p style="font-size:9px;">Sent from web.</p>`;
const mailOptions = {
from: 'Xxxxx <xxxxxx@gmail.com>',to: email,subject: subject,html: html
};
transporter.sendMail(mailOptions,(err,info) => {
console.log("SENDING EMAIL");
if (err) {
console.log("email NOT sent: " + err);
res.send(err.toString());
}
else {
console.log("email sent: " + info.response);
res.status(200).send(html);
}
});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。