gpt4 book ai didi

javascript - 尽管设置了 MAIL_URL 环境变量,Meteor 邮件仍不发送

转载 作者:行者123 更新时间:2023-11-28 07:23:40 24 4
gpt4 key购买 nike

我在终端中收到此错误消息“邮件未发送;要启用发送,请设置 MAIL_URL 环境变量。”尽管设置了 MAIL_URL 环境变量。在此消息之后,整个邮件内容 html 将转储到终端中。我使用 2 个meteor 包来发送电子邮件:yogiben:pretty-emails 和带有 mailgun api 服务的电子邮件。

这是邮件配置和发送电子邮件的源代码:

if Meteor.isServer
Meteor.startup ->
process.env.MAIL_URL = 'smtp://sandboxid.mailgun.org:mypassword@smtp.mailgun.org:587'
return


PrettyEmail.options =
from: 'primaryemail@gmail.com'

siteName: 'Meteor Test'
companyAddress: 'sdfsf, gdfg-df'
companyName: 'Code to Create'
companyUrl: 'http://example.com'

Accounts.sendVerificationEmail ->
Meteor.userId()

此文件保存在 Project_Directory/both/_config 目录中。我目前正在本地 ubuntu 服务器上开发这个应用程序。

最佳答案

我认为对 sendVerificationEmail 的调用应该是:

Accounts.sendVerificationEmail Meteor.userId()

根据 http://docs.meteor.com/#/full/accounts_sendverificationemail 的文档

如果该代码与您正在使用的代码完全相同,那么您可能会因每段代码的运行顺序(回调异步运行)而遇到问题。启动回调将在 PrettyEmail.optionsAccounts.sendVerificationEmail

之后运行

如果您按如下方式缩进这两个部分,它应该按预期工作:

if Meteor.isServer
Meteor.startup ->
process.env.MAIL_URL = 'smtp://sandboxid.mailgun.org:mypassword@smtp.mailgun.org:587'

PrettyEmail.options =
from: 'primaryemail@gmail.com'
siteName: 'Meteor Test'
companyAddress: 'sdfsf, gdfg-df'
companyName: 'Code to Create'
companyUrl: 'http://example.com'

Accounts.sendVerificationEmail Meteor.userId()

如果失败,也可能值得在运行应用程序之前设置 MAIL_URL,例如:

MAIL_URL="smtp://sandboxid.mailgun.org:mypassword@smtp.mailgun.org:587" meteor

编辑:您的示例代码不安全:如果您将此代码保留在“both”目录中,则访问您网站的任何人都将能够看到您的 mailgun 凭据。您应该将服务器代码放在“服务器”目录中,或者至少将 MAIL_URL 设置在代码之外,如上所示。

关于javascript - 尽管设置了 MAIL_URL 环境变量,Meteor 邮件仍不发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29998893/

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