【问题标题】:How to send localhost email and capture it using Thunderbird?如何发送 localhost 电子邮件并使用 Thunderbird 捕获它?
【发布时间】:2017-10-15 23:45:06
【问题描述】:

我正在尝试从 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"
  }

【问题讨论】:

  • 是的,你应该把它放在 development.rb 中,尽管它必须是 Thunderbird 吗?试试这个mailcatcher.me

标签: ruby-on-rails thunderbird


【解决方案1】:

正如@aniket-rao 建议的那样:使用Mailcatcher 来完成这一切。无需安装本地后缀服务器和摆弄收件箱。来自文档:

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 上运行的本地 Web 应用程序上可见。

【讨论】:

    【解决方案2】:

    试试这个

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-07
      • 1970-01-01
      • 2018-12-14
      • 2014-05-20
      • 2016-09-20
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多