Bruno Fernandes
Bruno Fernandes

Reputation: 145

How to send localhost email and capture it using Thunderbird?

I'm trying to send an email from rails and capture it using thunderbird.

This is my mailer:

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

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

I followed this instructions to configure thunderbird locally and it is working fine. https://gist.github.com/raelgc/6031274

I'm not sure how to config rails.

What should I put here in development.rb ?

config.action_mailer.delivery_method = :smtp

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

Upvotes: 1

Views: 1923

Answers (2)

datenimperator
datenimperator

Reputation: 308

As @aniket-rao suggested: Use Mailcatcher which does all this. No need to install a local postfix server and fiddle with inboxes. From the docs:

MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface. Run mailcatcher, set your favourite app to deliver to smtp://127.0.0.1:1025 instead of your default SMTP server, then check out http://127.0.0.1:1080 to see the mail that's arrived so far.

In your Rails environment use this configuration to send email to Mailcatcher:

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

Your email will be visible on the local web app running on port 1080.

Upvotes: 2

Aniket Tiwari
Aniket Tiwari

Reputation: 3998

Try this

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

Upvotes: 0

Related Questions