【问题标题】:Sending an email from my ROR4 app从我的 ROR4 应用程序发送电子邮件
【发布时间】:2014-01-08 11:47:25
【问题描述】:

我知道以前有人问过这个问题,但我仍然无法让它工作,即使控制台说它有。

emailer.rb

    class Emailer < ActionMailer::Base
  default from: "from@example.com"



  def welcome_email()

      @url  = 'http://example.com/login'
      email_with_name = "#{My Name} <#{MyEmail@gmail.com}>"
      mail(to: email_with_name, subject: 'Test')
  end

end

environment.rb #(在配置中)

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'example.com',
    user_name:            'myemail@gmail.com',
    password:             'mypassword',
    authentication:       'plain',
    enable_starttls_auto: true  }

为了测试,我将Emailer.welcome_email().deliver 放入控制台

有人告诉我,如果我的设置不正确,有可能不会出现错误。

这些设置对每个人来说都合适吗?如果是这样,我还可以在哪里检查以找到问题?

谢谢

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-4 actionmailer


【解决方案1】:

我遇到了和你一样的问题。所有数据似乎都在通过,但没有发送任何电子邮件。实际上,我在服务器日志中看到了一个连接错误,这表明我的应用无法连接到 Google。

我最终找到了这个指令集http://www.leemunroe.com/send-automated-email-ruby-rails-mailgun/ 并创建了一个免费的 MailGun 帐户。这真的很简单。它在大约 30 分钟内启动并运行,而我使用 Google + SMTP 失败所花费的时间则不同。

希望这会有所帮助。祝你好运。

【讨论】:

    猜你喜欢
    • 2010-12-20
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 2020-05-24
    • 2011-05-08
    • 2011-08-06
    • 2011-02-03
    • 1970-01-01
    相关资源
    最近更新 更多