ruby-on-rails - 如何使用rails 4通过localhost发送邮件?

标签 ruby-on-rails ruby email actionmailer postfix-mta

我在 ruby​​ 中搜索了相当于非常简单的 PHP 邮件功能。

我看http://guides.rubyonrails.org/action_mailer_basics.html我尝试使用它,但不清楚。

我在指南和其他人的回复中找到的唯一例子是关于“gmail smtp”。 我不想使用gmail smtp,只想使用本地smtp服务器来测试邮件功能,就像在WAMP上一样。

我尝试了:sendmail Delivery_method,但它响应“/bin/sendmail不存在”,所以我在本地安装postfix并将此配置添加到development.rb:

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :sendmail
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true  

我的 Rails 服务器日志:

UserMailer#welcome_email: processed outbound mail in 2.4ms

Sent mail to [email protected] (59.5ms) Date: Wed, 10 Dec 2014 12:08:02 +0100 From: [email protected] To: mytruedomain.com Message-ID: <[email protected]> Subject: test Mime-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

un test

但我从未在 [email protected] 的邮箱中收到它...

编辑:当我观看 postfix 日志时:

postfix/error[6335]: 7ECBD5C29E5: to=, relay=none, delay=0.14, delays=0.08/0/0/0.06, dsn=5.0.0, status=bounced (mytruedomain.com)

我的本​​地后缀缺少/需要什么具体配置?

那么我该如何发送邮件呢?我只是想发邮件,我不明白怎么这么复杂!

最佳答案

首先测试您的服务器是否正常工作:

date | mail -s test <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ee7f1ebecb0f0fff3fbdefaf1f3fff7f0b0fdf1f3" rel="noreferrer noopener nofollow">[email protected]</a>

然后配置您的应用程序以使用 smtp 发送电子邮件:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address => "localhost",
  :port => 25,
  :domain => "domain.com",
}

关于ruby-on-rails - 如何使用rails 4通过localhost发送邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27400039/

相关文章:

ruby - 用 '-' 或 '_' 命名 ruby gem 有什么注释或规则吗?

ruby-on-rails - 如何在 Ruby 中创建一个新的 Date 实例

转发时 HTML 电子邮件布局中断 - 使其在 Word 2003 HTML 编辑器中幸存下来

ruby-on-rails - Ffmpeg 的时间限制

javascript - 字符 "d' "becoming "d'”显示时

mysql - 使用 MySQL 子句 "Use index(' index_name')"using ActiveRecord 的最佳方式

c# - 在 C# 中拆分字符串中的子字符串

ruby-on-rails - Omniauth:如何在运行时设置身份验证提供程序详细信息

ruby-on-rails - 努力在 OSX Lion 上安装 pg gem - "missing required architecture x86_64 in file for architecture x86_64"

php - 如何将投票按钮限制为 'To' 地址而不是通过 powershell 在 outlook 中发送到 'Cc'?