gpt4 book ai didi

email - Nodemailer - 电子邮件发送但不接收

转载 作者:行者123 更新时间:2023-12-03 23:22:43 24 4
gpt4 key购买 nike

我正在使用 feathersjs 构建一个 API,我需要发送一封带有附件的电子邮件。
电子邮件似乎已发送,但我什么也没收到。
在我的 mail.service.js

const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
secure: false, // secure:true for port 465, secure:false for port 587
auth: {
user: 'gil.felot@myaccount.com',
pass: 'MyPassWord'
}
});

// Check the connection to the service.
transporter.verify(function(error, success) {
if (error) {
console.log(error);
} else {
console.log('Server is ready to take our messages');
}
});
然后在我的钩子(Hook)里
hook => {
const file = hook.params.file;

const email = {
from: 'gil.felot@myaccount.com', // sender address
to: 'mygmailaccount@gmail.com', // list of receivers
subject: 'Test Nodemailer', // Subject line
// text: req.body.text, // plaintext body
html: '<b>Hello world 🐴</b>', // html body
attachments: [
{
filename: file.originalname,
contents: new Buffer(file.buffer, 'base64'),
encoding: 'base64'
}
]
};

return hook.app.service('mail').create(email)
.then(function (result) {
console.log('Sent email', result);
}).catch(err => {
console.log(err);
});
}
然后我得到了

Server is ready to take our messages

Sent email

Object {from: "gil.felot@myaccount.com", to: "mygmailaccount@gmail.com", subject: "Test Nodemailer", html: "Hello world 🐴"}


我不知道如何检查问题来自哪里。

最佳答案

我在创建邮件时丢失了 from 部分,而我能够通过 google smtp 发送邮件,但我自己的 smtp 在上述配置中失败

正在与谷歌合作

var mailOptions = { to: email, subject: 'Forgot Password', html: mailData };

也使用我的 smtp:
var mailOptions = { from: 'serverName.com', to: email, subject: 'Forgot Password', html: mailData };

考虑在定义 nodemailer 时添加名称配置也一样
let transporter = nodemailer.createTransport({
name: 'example.com' // <= Add this
host: 'smtp.example.email',
port: 587,

关于email - Nodemailer - 电子邮件发送但不接收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45305050/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com