Rails 3 sendgrid 支持无法发送电子邮件...尝试了我在网络上找到的所有内容...:P

发布于 2024-11-18 17:47:59 字数 871 浏览 2 评论 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 => "[email protected]",
        :password => "password",
        :enable_starttls_auto => true
  }

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

我尝试过各种其他随机组合,但均无济于事。有人有更多想法吗?

谢谢!

So I've got a sendgrid account, and I'm trying to get Rails 3 to send emails through it... Here are some of my settings:

#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 => "[email protected]",
        :password => "password",
        :enable_starttls_auto => true
  }

I'm using Ubuntu Mint, and sendmail can send emails, I can also telnet into smtp.sendgrid.net 587 successfully.

I've tried all kinds of other random combinations of things to no avail. Anyone got any more ideas?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅紫色的梦幻 2024-11-25 17:47:59

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

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

Try altering your postfix configuration file to send emails via a relayhost. I'm guessing you're ISP is blocking your outgoing port 25. Check out the link below:

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

软糯酥胸 2024-11-25 17:47:59

我不确定你的问题是否和我的一样,但我在浪费了半天时间后才弄清楚如何使 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控制台”时”,我收到一条错误消息“main:Object (NameError) 的未定义局部变量或方法‘config’”

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

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

之后它就像魔术一样工作。希望这能有所帮助,如果不是你,至少还有其他一些不幸的新手......

编辑:

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

如果您找到问题的答案,请将其发布在这里...

I'm not sure whether your problem is the same as mine, but I just figured out how to make SendGrid work after wasting half a day on it. Disclaimer: I am VERY new to RoR - just started playing with simple apps two-three days ago. My problem seemed to be something that only a newbie can encounter...

Anyway, without further ado, this is what happened. I added the recommended lines to 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
}

Then I tried to send an email and got a strange behavior:

  • The development log said it was sent
  • Well, SendGrid didn't even try to send it
  • When I tried to go into "rails console", I got an error saying "undefined local variable or method `config' for main:Object (NameError)"

It turned out that I have to enclose the config.* stuff in the following:

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

It worked like magic after that. Hope this helps, if not you, some other hapless newbie at least...

EDIT:

Well, I spoke too early. With the modifications above I am able to send and receive the email ONLY if invoking the Emailer from the rails console. If I call it from within the app, the development log says the email was sent, but I don't receive it... What is the difference between the console environment and the app? Note that when I follow the postfix instructions on SendGrid and start postfix, the email gets send from the app alright.

If you have found the answer to your problem, please post it here...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文