Welcome Guest | Login

Sending e-mails

Aiuto! I can't get my application to send e-mails! Gmail works fine while developing at home, but (what I thought) the easier way of using smtp or sendmail doesn't work for me. I use ActionMailer and added this to production.rb:

ActionMailer::Base.server_settings = {
 :address  => "mail.mydomain.se",
 :port  => 25,
 :domain  => "mydomain.se",
 :user_name  => "admin+mydomain.se",
 :password  => "*****",
 :authentication  => :login
}

ActionMailer::Base.delivery_method = :sendmail  
ActionMailer::Base.perform_deliveries = true  
ActionMailer::Base.raise_delivery_errors = true  
ActionMailer::Base.default_charset = "utf-8"


I've created the admin mail account as well. What did I miss???

2007-01-18 02:43 PM

I am having the same issue. I am trying to send a "hello world" style test e-mail using ActionMailer with no luck. My config looks the same as above. I assume that if I enter my HostingRails username/pass that I should be able to send a test e-mail through the HostingRails SMTP server from my local dev environment. Is this correct or would there be restrictions (to certain IPs, etc.)? Also, are there any good tips to debug this?

One last thing, I've been coding my test e-mail based on the following tutorial: http://wiki.rubyonrails.org/rails/pages/HowToSendEmailsWithActionMailer
Are there any other good tutorials out there (to help me troubleshoot)? Thx for any help.

2007-01-18 08:59 PM

I've been able to send out emails on my sites without adding anything to my environment.rb (or production.rb).

Would you mind posting your controller and model code you are using to generate and send the emails? That might be helpful.

2007-01-18 09:43 PM

But surely you must add mail account information somewhere? Since I use gmail at home and (hopefully) something else here, I put that data into Environments/development.rb and Environments/production.rb.

Otherwise it works just fine and I've followed all the excellent advice there is (changes in routes.rb, the controllers etcetera). But no chages in the ActionMailer files.

2007-01-19 04:55 AM

Hi there - all you need is this (and just put it at the bottom of your environment.rb):

ActionMailer::Base.delivery_method = :sendmail  
ActionMailer::Base.perform_deliveries = true  
ActionMailer::Base.raise_delivery_errors = true  
ActionMailer::Base.default_charset = "utf-8"

Yes. You don't need server settings.

then your app will use sendmail to send out emails and it goes quick.  This is exactly what we have here with this forum app; when you submit a post everyone watching immediately gets notified.  

2007-01-19 05:57 AM

I'll be damned... it works! :)

But the mail is sent with my email as the sender. I would like admin@mysite.se to be the sender. Well, that shouldn't be too complicated at this stage I suppose. Thanks a lot!

2007-01-19 06:45 AM

Yeah for the from field just have YOUR NAME <admin@mysite.se> and that should work.  

2007-01-19 05:21 PM

Hmm, I'm still having issues. I am trying to just send a hello-world welcome e-mail. I am calling the controller directly (i.e. http://mydomain.org/account/welcome). Here is my code:

------------Account Controller-------------------

def welcome
 NcMailer::deliver_signup_thanks
end

------------Mailer-------------------

class NcMailer < ActionMailer::Base
 def signup_thanks
   @recipients = "me@gmail.com"
   @from = "accounts@mydomain.org"
   @subject = "Thank you for registering with our website"
 end
end

-----------View (signup_thanks.rhtml)---------------

Thanks for signing up with My Website!

-----------environment.rb-------------------

ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.perform_deliveries = true  
ActionMailer::Base.raise_delivery_errors = true  
ActionMailer::Base.default_charset = "utf-8"

------------------------

Any help would be great. Thanks a lot.

2007-01-19 08:29 PM

Use

@from = "Your Name <accounts@mydomain.org>"

what errors are you seeing?  what's the problem now exactly?

2007-01-19 10:10 PM

Thanks for the reply and sorry for the ambiguity. I can receiving the following error:

Errno::ENOENT in AccountController#welcome
No such file or directory - /usr/sbin/sendmail -i -t

It's looking for the path to sendmail and can't find it. This looks like a *nix path but I am attempting to send these mails from my local instance running on Windows. Can I use ActionMailer with the sendmail method on Windows? If not, is there an alternative so that I can still test this locally (SMTP)?

2007-01-20 07:02 AM

Hi there - yeah don't use sendmail on your windows machine.  

use:
ActionMailer::Base.delivery_method = :smtp  
ActionMailer::Base.server_settings = {  
 :address => "domain-of-smtp-host.com",
 :domain => "domain-of-sender.com",
 :port => 25,  
 :authentication => :login,  
 :user_name => "your_user_name",  
 :password => "*****" }  
ActionMailer::Base.perform_deliveries = true  
ActionMailer::Base.raise_delivery_errors = true  
ActionMailer::Base.default_charset = "utf-8"

2007-01-22 04:24 PM

William, thanks for all of your help. I have narrowed this issue down to a SMTP connection issue (probably related to my ISP/network). I pushed this code out to my production server and it works great. I just need to figure out a way to get this working on my dev/local instance. I'll get there!

Thx again.

2007-01-23 10:03 PM

2007-05-15 10:14 AM

RAILS 2.0 WARNING...

In Rails 1.x, use this:
ActionMailer::Base.server_settings

In Rails 2.0, use this:
ActionMailer::Base.smtp_settings

Note that "smtp" replaces "server"

Here's the full Rails 2.0 style:

ActionMailer::Base.delivery_method = :smtp  
ActionMailer::Base.smtp_settings = {  
 :address => "domain-of-smtp-host.com",
 :domain => "domain-of-sender.com",
 :port => 25,  
 :authentication => :login,  
 :user_name => "your_user_name",  
 :password => "*****" }  
ActionMailer::Base.perform_deliveries = true  
ActionMailer::Base.raise_delivery_errors = true  
ActionMailer::Base.default_charset = "utf-8"

2008-04-03 10:02 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up.