我正在服务器上运行节点js api。它具有注册端点和激活端点。注册后,api将激活链接发送到用户的电子邮件ID。我正在使用nodemailer发送邮件。大多数情况下,邮件延迟了将近3-4分钟。有时它无法交付。这是发送邮件的代码,
import mailer from "nodemailer";
// Use Smtp Protocol to send Email
var smtpTransport = mailer.createTransport({
service: "Gmail",
secure: false,
requireTLS: true,
auth: {
user: "example.in@gmail.com",
pass: "password_for_sender_email"
}
});
const mailMessage = (message:string,receiver:string) =>{
const mail:object = {
from: "My Email Name<example.in@gmail.com>",
to: receiver,
subject: "Activation link",
text: message
}
return mail;
}
export class Email{
public Send = async (receiver:string, message:string) =>{
smtpTransport.sendMail(mailMessage(message, receiver), function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent");
}
smtpTransport.close();
});
}
}
问题出在代码中还是任何服务器问题? 看一下我的服务器内存使用情况。 (全部以MB为单位)
此处的可用空间为493MB。我认为这足以处理邮件传递。延迟交货可能是什么问题?