微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Nodemailer在失眠中工作,但不在我的网站上

如何解决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);
        }  
        
    });
});

enter image description here

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?