我在 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/