Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Sending mails on a mac
4 Posts
Sending mails on a mac

Hi,

I've written a function to send my contactform content to me. But sometimes, it's working and sometimes it isn't.

http://pastie.org/500904

The log shows that the mail is send but it I'm not receiving one!

Hi Wouter!

Have you set config.action_mailer.raise_delivery_errors = true for your current environment? If not, your mailer will fail silently whether it sends or not.

You could try adding something like this to your code:

begin

   Notifier.deliver_contact(@contact.name, @contact.address, @contact.city, @contact.email, @contact.telephone, @contact.subject, @contact.message, @contact.language, @contact.ip)

rescue => e logger.error "Email didn't send, error message:\n" + e end

This will help you pinpoint whether the mail is being sent or not.

If it's not, hopefully the error message in your log will shed some light on why not.

If it is - maybe it's a problem with your server. It might even be getting put into your junk mail?

Hope that helps?

Hi Gavin,

Thanks for your response. I think I've located the problem. For some reason the sendmail isn't working. I've changed the settings to smtp and now everything works fine.

It's a good idea to put the code in a try-catch block, I'll do that for the whole application.

Hi Wouter,

OS X by default uses Postfix as it's mail system, which provides the sendmail command. Typically you will have trouble using this to send email out to remote servers though as your development machine running on a home/broadband IP wouldn't be a trusted source. To get around this and have sendmail work most of the time, you can set it up to relay all email through a trusted SMTP server such as your GMail account - there is a good howto on this here http://www.riverturn.com/blog/?p=239

On the plus side sorting the Postfix relay out also allows mail to work for any local PHP/Cgi/whatever development you are doing.

4 Posts
Login to add your message