0

所以我有一个 sendgrid 帐户,我正在尝试让 Rails 3 通过它发送电子邮件......这是我的一些设置:

#development.rb

  config.action_mailer.default_url_options = { :host => "smtp.sendgrid.net" }

  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
        :address => "smtp.sendgrid.net",
        :port => '587',
        :domain => "place.com",
        :authentication => :plain,
        :user_name => "me@place.com",
        :password => "password",
        :enable_starttls_auto => true
  }

我正在使用 Ubuntu Mint,并且sendmail可以发送电子邮件,我也可以smtp.sendgrid.net 587成功 telnet 进入。

我尝试了各种其他随机组合的东西都无济于事。有人有更多的想法吗?

谢谢!

4

2 回答 2

0

尝试更改您的后缀配置文件以通过中继主机发送电子邮件。我猜你的 ISP 正在阻止你的传出端口 25。查看下面的链接:

http://wiki.sendgrid.com/doku.php?id=postfix

于 2011-07-15T18:54:40.520 回答
0

我不确定您的问题是否与我的相同,但我只是在浪费了半天时间后才弄清楚如何使 SendGrid 工作。免责声明:我对 RoR 非常陌生 - 两三天前刚开始玩简单的应用程序。我的问题似乎是只有新手才能遇到的事情......

无论如何,事不宜迟,这就是发生的事情。我在 environment.rb 中添加了推荐的行:

config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true

ActionMailer::Base.smtp_settings = {
    :user_name => "your_username",
    :password => "your_password",
    :domain => "yourdomain.com",
    :address => "smtp.sendgrid.net",
    :port => 587,
    :authentication => :plain,
    :enable_starttls_auto => true
}

然后我尝试发送电子邮件并得到一个奇怪的行为:

  • 开发日志说已发送
  • 好吧,SendGrid 甚至没有尝试发送它
  • 当我尝试进入“rails 控制台”时,我收到一条错误消息,提示“未定义的局部变量或方法 `config' for main:Object (NameError)”

事实证明,我必须将 config.* 内容包含在以下内容中:

YourApplicationName::Application.configure do
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.raise_delivery_errors = true
end

在那之后它就像魔术一样起作用。希望这对您有所帮助,如果不是您,至少还有其他一些不幸的新手...

编辑:

好吧,我说得太早了。通过上面的修改,我只有在从 rails 控制台调用 Emailer 时才能发送和接收电子邮件。如果我从应用程序内调用它,开发日志显示电子邮件已发送,但我没有收到它......控制台环境和应用程序有什么区别?请注意,当我按照 SendGrid 上的 postfix 说明并启动 postfix 时,电子邮件会从应用程序发送正常。

如果您找到了问题的答案,请在此处发布...

于 2011-09-22T07:58:02.203 回答