简体   繁体   English

验证电子邮件是否成功发送 nodemailer (sails.js)

[英]verify if email is delivered successfully nodemailer (sails.js)

I'm using nodemailer module to send email in my sails.js project.我正在使用nodemailer模块在我的 Sails.js 项目中发送电子邮件。 Now i'm wondering if there is a way that i could know if the email is delivered successfully or the email is somehow failed due to some attachment or may be wrong email address.现在我想知道是否有一种方法可以知道电子邮件是否已成功发送或电子邮件因某些附件而以某种方式失败或可能是错误的电子邮件地址。

how can i make it sure that the email address is valid or not ?我如何确保电子邮件地址有效? or the email is being delivered to the relevant email address successfully or not ?或者电子邮件是否成功发送到相关电子邮件地址?

I've read the nodemailer documentation and also have done some R&D on it but so far i'm not able to find anything productive.我已经阅读了 nodemailer 文档并对其进行了一些研发,但到目前为止我找不到任何富有成效的东西。

Please let me know if there is a way to confirm about email or not.请让我知道是否有办法确认电子邮件。

Thanks.谢谢。

It's simple.这很简单。 sendMail has a callback as an argument. sendMail有一个回调作为参数。 You just checking if some error is exists in this callback.您只需检查此回调中是否存在某些错误。

transport.sendMail({}, (error, result) => {
  if (error) return console.error(error);
  return console.log(result);
});

Or you can use sails-service-mailer package for sending mails - https://github.com/ghaiklor/sails-service-mailer .或者你可以使用sails-service-mailer包来发送邮件 - https://github.com/ghaiklor/sails-service-mailer Then you can write your code like this然后你可以像这样写你的代码

SmtpMailer
  .send({})
  .then(console.log.bind(console))
  .catch(console.error.bind(console));

If you want to check pool or something then there is no possibility, I suppose.如果你想检查池或其他东西,我想是不可能的。 If you send mail to non-existing email address it sends as usual, just not be received by recipient.如果您将邮件发送到不存在的电子邮件地址,它会照常发送,只是收件人不会收到。 Anyway, you can check if mail was added to pool only.无论如何,您可以检查邮件是否仅添加到池中。

UPD: transport has a Promise API as well (see https://nodemailer.com/usage/ ) so there is no need in custom wrappers like mine sails-service-mailer anymore. UPD: transport也有一个 Promise API(参见https://nodemailer.com/usage/ ),所以不再需要像我的sails-service-mailer这样的自定义包装sails-service-mailer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM