如何在nodemailer中使用除了gmail以外的自定义邮件?

huangapple go评论55阅读模式
英文:

How to use custom mails with nodemailer other than gmail?

问题

我在一个微服务项目或 CRM 中工作。为了发送邮件,我正在使用 nodemailer 与 Gmail 服务,但它只适用于 Gmail 邮箱。但我需要从其他邮箱发送邮件,比如 .....@iteccounsel.com 或 ....@quadque.digital,但这不起作用。此外,我不知道如何为这些邮箱设置应用程序密码。目前我正在使用我用于登录的原始密码。我尝试设置应用程序密码,但在这些邮箱的设置中找不到任何选项。那么,我需要改变什么以使其他邮箱正常工作?

Nodemailer 代码:

let transporter = nodemailer.createTransport({
    port: 465,
    secure: true,
    service: "gmail",
    auth: {
      user: ".......@quadque.digital",
      pass: ".........",
    },
  });

我需要在我的代码中做任何更改吗?在服务中我应该使用什么代替 Gmail?

英文:

I am working in an micro service project or crm. For sending mail I am using nodemailer with service gmail which is only working with gmail emails. But I need to send mail from other emails such as .....@iteccounsel.com or ....@quadque.digital which is not working. Also I don't know how to set app passwords for these mails. Currently I am using the original password which I use to login. I tried to set app password but didn't find any settings for these mails. So what to change to make other mails work ?

Nodemailer code :

let transporter = nodemailer.createTransport({
    port: 465,
    secure: true,
    service: "gmail",
    auth: {
      user: ".......@quadque.digital",
      pass: ".........",
    },
  });

Is there anything I need to change in my code ? And what should I use instead of gmail in service ?

答案1

得分: 1

你可以从nodemailer.createTransport中移除service属性。

添加一个名为host的属性,并填写你的自定义SMTP主机。
另外,如果你改变端口从465,请记得修改secure属性。

示例:

let transporter = nodemailer.createTransport({
    host: 'something.domain.com',
    port: 465,
    secure: true, // 如果你想要其他端口而不是465,请将其改为false
    auth: {
      user: 'username@domain.com', // 你的电子邮件地址
      pass: 'password' // 你的密码
    }
  });

最后,你可以使用这个传输器来发送邮件。
希望这有所帮助。

问候。

英文:

You can remove the service prop from your nodemailer.createTransport.

Add a prop named host and fill it with your custom smtp host.
Also, remember to change secure prop in case you change the port from 465.

Example:

let transporter = nodemailer.createTransport({
    host: 'something.domain.com',
    port: 465,
    secure: true, // Change it to false if you wanted another port than 465
    auth: {
      user: 'username@domain.com', // Your email address
      pass: 'password' // Your password
    }
  });

Finally, you can use the transporter to send mail.
I hope this helps.

Regards.

huangapple
  • 本文由 发表于 2023年4月17日 12:19:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76031696.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定