我部署了带有联系表的rails5网站。我使用action-mailer和gmail向我发送了联系表格(通过我的gmail帐户)。我在Google帐户中使用应用密码进行了两步验证。问题是大多数时候都可以正常工作,但有时我没有收到邮件。我认为这是由Google提供的,因为如果是从我的代码获得的,为什么我通常会收到它们。我希望有人有一个主意。我还有第二个问题,从我的动作邮件程序配置中调用凭据的语法是否正确?
address: 'smtp.gmail.com',
port: 587,
domain: 'domain.com',
user_name: ['Rails.application.credentials.dig(:production, :GMAIL_USER_NAME)'],
password: ['Rails.application.credentials.dig(:production, :GMAIL_PASSWORD)'],
authentication: 'plain',
enable_starttls_auto: true }
在我的凭据中。yml.enc:
GMAIL_USER_NAME: [email protected]
GMAIL_PASWORD: applicationgmailpassword
因为您收到了一些电子邮件,所以我认为问题在于Google,而不是您的应用程序,对。
它们是否出现在您的垃圾邮件文件夹中?
您可以尝试改用Mailgun之类的东西。试试本教程:https://www.leemunroe.com/send-automated-email-ruby-rails-mailgun/
关于您的第二个问题,我认为您需要重新格式化。
如何构造您的certificate.yml.enc文件:
# no need to specify between environments # no need to capitalize gmail_user_name: [email protected] gmail_password: thisIsNotMyRealPassword
然后调用这些变量:
Rails.application.credentials.gmail_user_name Rails.application.credentials.gmail_password
因此,在您的ActionMailer配置文件中,您应该这样做:
...
user_name: Rails.application.credentials.gmail_user_name,
password: Rails.application.credentials.gmail_password,
...