views:

580

answers:

3

I've been working on learning to use Rails the last couple days and I've run into something that I haven't been able to solve with Google.

So I'm just creating a basic contact form that sends an email. Everything seems to be working ok in testing, which tells me that the form is working, and ActionMailer was implemented correctly, however, I'm having trouble configuring ActionMailer. I'm running OSX 10.6.2. I have postfix running and have verified that it's running using telnet localhost 25. When I try to use the form I get a "Connection refused" error.

This is my current configuration:

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

I thought I might need to set :domain but I'm kind of confused on what that should be set to in this situation.

A: 

Does it work if you substitute '127.0.0.1' for 'localhost' to see if this is an IPv4 vs. IPv6 thing or an issue with your resolver?

tadman
Hm, no that didn't work either.
seth
If the output of "netstat -na | grep LISTEN" shows "tcp4 0 0 *.25 *.* LISTEN" then you should be getting a connection. If it shows "::1.25" you might be in IPv6 mode. If you have any kind of local firewall, including Little Snitch, this could be blocking your calls, too. The only way to know for sure is to attempt a connection from Ruby directly, such as through a unit test.
tadman
+2  A: 

My life has been roughly 100x easier running :sendmail on my mac as a delivery method on my mac rather than :smtp, you might want to try giving that a shot. In this answer, I am assuming that you just want mail delivery on your Mac and don't actually care how it works.

The other thing I do, if I'm going to be connected to the net all the time on a project, is to configure my outgoing ActionMailer-originated mail to go through gmail rather than my local mac.

ActionMailer::Base.delivery_method = :smtp

ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
  :address        => "smtp.gmail.com",
  :port           => 587,
  :domain         => "example.com",
  :authentication => :plain,
  :user_name  => "[email protected]",
  :password  => "secret"
}

This is for a custom domain called example.com that is set up on google apps for domains. You can also just create a gmail account and send things through there. (By changing all instances of example.com to gmail.com)

corprew
A: 

You need to start the postfix daemon. you can tell if your port is open by typing in a terminal

telnet localhost 25

which will try to connect to the 25 port. It wont connect if postfix isnt running, if it does, hit ctl-] to stop the connection and 'quit' to quit telnet.

If it doesn't connect, you need to start the postfix daemon:

sudo launchctl start org.postfix.master

and then try to connect with telnet. it should connect. Now you are ready to send emails from your ActionMailer class.

sudo launchctl stop org.postfix.master

stops the postfix daemon

Jed Schneider