如何发送localhost电子邮件并使用Thunderbird捕获它?

时间:2017-10-15 23:45:07

标签: ruby-on-rails thunderbird

我尝试从rails发送电子邮件并使用thunderbird捕获它。

这是我的邮件:

def hello_world
    from = 'bruno@localhost'
    subject = 'Hello World'
    to = 'bruno@localhost'

    main to: to, from: from, subject: subject
  end

我按照此说明在本地配置thunderbird,它工作正常。 https://gist.github.com/raelgc/6031274

我不确定如何配置rails。

我应该在development.rb中添加什么内容?

config.action_mailer.delivery_method = :smtp

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

2 个答案:

答案 0 :(得分:2)

正如@ aniket-rao所建议:使用Mailcatcher完成所有这些操作。无需安装本地postfix服务器并摆弄收件箱。来自文档:

  

MailCatcher运行一个超级简单的SMTP服务器,该服务器捕获发送给它的任何消息以显示在Web界面中。运行mailcatcher,将您喜欢的应用程序设置为smtp://127.0.0.1:1025而不是默认的SMTP服务器,然后查看http://127.0.0.1:1080以查看到目前为止已到达的邮件。

在您的Rails环境中,使用此配置向Mailcatcher发送电子邮件:

# use Mailcatcher
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 }

您的电子邮件将显示在1080端口上运行的本地网络应用中。

答案 1 :(得分:0)

试试这个

 mail(to: to, from: from, subject: subject)