This weekend I was just looking for infos about the new Action Mailer. Your sense of providing a screencast of exactly the thing I'm looking for is fantastic! great work!
Nice casts. If you are on Mac, you can use MockSMTP (http://mocksmtpapp.com) to test your mailer model.
It's a native mac application that mocks SMTP and display them in a nice GUI that looks like a mail reader. It supports multi-part mails and attachements.
I've been hedging on when to bite the Rails 3.0 bullet, but this tipped the scales.
Two things: I've noticed a problem with the video playback in Snow Leopard QT. The screen won't refresh unless you're moving the mouse or a lot of screen elements have changed. This even happens on the older casts. Try watching the intro all the way through, for instance, and you begin talking but the screen hasn't changed. Pausing and restarting causes the screen to update. I've noticed this on upgraded OSX as well as factory installs OSX.
Second, what are you using for syntax coloring in Terminal? Do you get it free from bash? I know you mentioned it in a cast a while back but I can't remember where. Maybe you could add your development environment to the About page.
@iain, using "join" is probably the best way so it is system independent. Thanks for pointing that out!
@Dave, I'm aware of the Snow Leopard problem, it's a bug with Animation codec in QuickTime. I'm hoping they fix it soon. You may want to use the iPod version in the meantime.
I don't use any syntax highlighting in Terminal. It's just a standard white on black theme.
When you say you can call "deliver" later on the email...can you provide an example of this? I would be very interested in asynchronous email delivery in Rails 3. Looks like it is getting closer but would like to learn more.
Nice screencast, as always.
If I remember correctly using TMail in 2.3 we can also just call create_mailer_method to get the TMail object and call deliver on it.
The dynamic methods of 2.3 with "deliver_mailer_method" are just fine with me.
But thanks for pointing out to move the sending of registration Emails out of the Observer into the controller. That's indeed a good point.
Other than that with 2.3 Mailer we can already compose multipart message with views, I fail to see the real difference on the surface. Maybe a lot has changed under the hood.
I tried in my machine and I had to change the user_name for smtp_settings in the initializer to include the domain name, e.g. from "railscasts" to "railscasts@railscasts.com", in order for an e-mail to be sent from my GoogleApp e-mail account.
I don't know if this problem happened to anybody. But I thought I just post the finding here.
I like getting rid of the magic methods, but supplying a hash for subject, from, etc. seems like quite a step backwards for an API, especially considering the changes to AR query API (hash keys became methods).
Nice screencast as usual. I would suggest using a config.action_mailer.smtp_settings statement in config/environments/*.rb instead of old the ActionMailer::Base.smtp_settings. Makes managing different ActionMailer configs for different environments easier.
I like the new action mailer. However, I am having trouble linking to things inside the email. I specified the host option as stated in the episode, but no luck.
first off, great video. i'm learning so much about rails through these screencasts so i really appreciate your work ryan.
i had a question: (not sure if anyone has faced this issue but) i'm getting an error when attempting to use my UserMailer in the users controller. the error i get is:
In case anyone else is having problems getting this to work with gmail apps, there is a little error in Ryan's demo code. In mail_setup.rb, user_name must be fully qualified, as in user@domain.tld, not just user. In the example, Ryan has
:user_name => "railscasts"
...where it should be...
:user_name => "railscasts@railscasts.com".
Hi!... I'm using ubuntu. After trying this casts. When i run the server, this is the output:
rails s
=> Booting WEBrick
=> Rails 3.0.0.rc application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/israel/Desktop/projects/mailit/config/initializers/setup_mail.rb:12: uninitialized constant DevelopmentMailInterceptor (NameError)
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/engine.rb:201
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/engine.rb:200:in `each'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/engine.rb:200
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/initializable.rb:25:in `instance_exec'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/initializable.rb:25:in `run'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/initializable.rb:50:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/initializable.rb:49:in `each'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/initializable.rb:49:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/application.rb:134:in `initialize!'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/application.rb:77:in `send'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/application.rb:77:in `method_missing'
from /home/israel/Desktop/projects/mailit/config/environment.rb:5
from /home/israel/Desktop/projects/mailit/config.ru:5:in `require'
from /home/israel/Desktop/projects/mailit/config.ru:5
from /usr/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
from /usr/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
from /home/israel/Desktop/projects/mailit/config.ru:1:in `new'
from /home/israel/Desktop/projects/mailit/config.ru:1
Note, you need to set config.action_mailer.delivery_method=:smtp
otherwise it will silently "work" in dev and test mode but never actually send email (as the default seems to be :test)
I realize this is 2 years (over) ago, but I thought I'd say I have the same problem. I found there was no .gitignore file so I created it with the README details, with no luck in an app I was working with called launchpage-rails. Seems to be a lack of config for the app.
Just an update - the issue appeared to be that the SMTP was not set up correctly. To rectify: you'll need to ensure your gem mail is set in your Gemfile. Next, create a setup_mail.rb file in config/initializers.
In case anyone else is having problems getting this to work with gmail apps, there is a little error in Ryan's demo code. In mail_setup.rb, user_name must be fully qualified, as in user@domain.tld, not just user. In the example, Ryan has
:user_name => "railscasts"
...where it should be...
:user_name => "railscasts@railscasts.com".
Hello, I'm using an interceptor to the User when registering on my site it receives a confirmation e-mail and I also know that a User has been registered .. S'p that only I am getting the mail, the User does not receive ...
Can anyone help me?
app/controllers/contatos_controller.rb
view plaincopy to clipboardprint?
ContatoMailer.contato_confirmation(@contato).deliver
no meu
config/initializers/setup_mail.rb
view plaincopy to clipboardprint?
require 'development_mail_interceptor'
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "localhost:3000",
:user_name => "usuario",
:password => "secret",
:authentication => "plain",
:enable_starttls_auto => true
}
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
no meu
lib/development_mail_interceptor.rb
view plaincopy to clipboardprint?
class DevelopmentMailInterceptor
I went through this tutorial on a new app with Rails 3.1.1 and it worked perfectly. However, I am now trying to use this on an existing app using Rails 3.0.9 with ActionMailer and DEVISE, and it does not work. I am pretty confident DEVISE uses ActionMailer based on the settings, but whenever I send an email to another use, they get the email and not me.
Has anyone been able to get this to work with DEVISE?
My problem is that I tried everything from your comments to make emails being sended but nothing works.
WebBrick says that email was sent, so what can be wrong?
Thanks for all of the awesome tutorials Ryan!!! I'm a total Rails/coding newbie and I managed to build a directory of printers for my IT dept with your help :). Now I followed this tutorial to try and get emails sent via a Gmail account to a list address (newprinter@domain.org) whenever a new printer is added to the directory. However, I'm stumped as to how to get this working with my rails app and I hope you or someone else can help. Please be gentle with me :). My app is a little different from your example code as I don't require a user registration, it's just a simple directory listing printers (make, model, IP address, IP address, etc.), and people can add/edit/delete printers from the "directory". I am including code from my app which I think is relevant below, although I could be wrong :). There's probably something horribly obvious to you or others which I am not seeing or able to figure out. I'd appreciate any help in advice on getting this working. Or if I should be going a different route to send the emails, please let me know.
This weekend I was just looking for infos about the new Action Mailer. Your sense of providing a screencast of exactly the thing I'm looking for is fantastic! great work!
Nice casts. If you are on Mac, you can use MockSMTP (http://mocksmtpapp.com) to test your mailer model.
It's a native mac application that mocks SMTP and display them in a nice GUI that looks like a mail reader. It supports multi-part mails and attachements.
Nice screencast, once again!
Shouldn't:
File.read("#{Rails.root}/public/images/rails.png")
be:
File.read(Rails.root.join('public', 'images', 'rails.png'))
Much nicer IMHO.
File attach, different views!
I am happy!
Amazing as usual mate... Can't wait for Rail 3.0 to be out of Beta and using it in live applications...
Plus new version ActionMailer API developer is Aussie... Wahoooooo!
I've been hedging on when to bite the Rails 3.0 bullet, but this tipped the scales.
Two things: I've noticed a problem with the video playback in Snow Leopard QT. The screen won't refresh unless you're moving the mouse or a lot of screen elements have changed. This even happens on the older casts. Try watching the intro all the way through, for instance, and you begin talking but the screen hasn't changed. Pausing and restarting causes the screen to update. I've noticed this on upgraded OSX as well as factory installs OSX.
Second, what are you using for syntax coloring in Terminal? Do you get it free from bash? I know you mentioned it in a cast a while back but I can't remember where. Maybe you could add your development environment to the About page.
Amazing railscast Ryan, thanks!
I'm finding a method to unit/functional testing outgoing emails like MockSMTP.app. But I'm using Linux to development. Have you got any idea? Thanks!
@iain, using "join" is probably the best way so it is system independent. Thanks for pointing that out!
@Dave, I'm aware of the Snow Leopard problem, it's a bug with Animation codec in QuickTime. I'm hoping they fix it soon. You may want to use the iPod version in the meantime.
I don't use any syntax highlighting in Terminal. It's just a standard white on black theme.
Rails make programming getting easy and simple. I think every web programming will use it... if they knew.
Thanks for Another casts Ryan.
Thanks for the tip about interceptors, Ryan! That's going to prove very useful, I'm sure.
Keep up the phenomenal work!
When you say you can call "deliver" later on the email...can you provide an example of this? I would be very interested in asynchronous email delivery in Rails 3. Looks like it is getting closer but would like to learn more.
What I'm missing is how to include an image inside the email.
text
img
more text.
Also, I get "Net::SMTPAuthenticationError: 530 5.7.0 Must issue a STARTTLS command first" errors when using the gmail stuff. Any ideas?
Nice screencast, as always.
If I remember correctly using TMail in 2.3 we can also just call create_mailer_method to get the TMail object and call deliver on it.
The dynamic methods of 2.3 with "deliver_mailer_method" are just fine with me.
But thanks for pointing out to move the sending of registration Emails out of the Observer into the controller. That's indeed a good point.
Other than that with 2.3 Mailer we can already compose multipart message with views, I fail to see the real difference on the surface. Maybe a lot has changed under the hood.
First of all, thank you for the screen cast.
I tried in my machine and I had to change the user_name for smtp_settings in the initializer to include the domain name, e.g. from "railscasts" to "railscasts@railscasts.com", in order for an e-mail to be sent from my GoogleApp e-mail account.
I don't know if this problem happened to anybody. But I thought I just post the finding here.
I like getting rid of the magic methods, but supplying a hash for subject, from, etc. seems like quite a step backwards for an API, especially considering the changes to AR query API (hash keys became methods).
Nice screencast as usual. I would suggest using a config.action_mailer.smtp_settings statement in config/environments/*.rb instead of old the ActionMailer::Base.smtp_settings. Makes managing different ActionMailer configs for different environments easier.
Hi,
I try to use this with delayed_jod.
UserMailer.delay.registration_confirmation(@user).deliver
undefined method `deliver' for #<Delayed::Backend::ActiveRecord::Job:0xb6277a48>
Any idea ?
Teuf: I think it should be: UserMailer.registration_confirmation(@user).delay.deliver
I like the new action mailer. However, I am having trouble linking to things inside the email. I specified the host option as stated in the episode, but no luck.
Ideas anyone? Im using rails 3 beta3.
This was great! Emailing via forms has long been a mystery to me. So simple even -I- can do it
first off, great video. i'm learning so much about rails through these screencasts so i really appreciate your work ryan.
i had a question: (not sure if anyone has faced this issue but) i'm getting an error when attempting to use my UserMailer in the users controller. the error i get is:
"uninitialized constant UsersController::UserMailer"
has anyone had this problem?
no worries, i figured out the problem. thanks again ryan! great videos!
In case anyone else is having problems getting this to work with gmail apps, there is a little error in Ryan's demo code. In mail_setup.rb, user_name must be fully qualified, as in user@domain.tld, not just user. In the example, Ryan has
:user_name => "railscasts"
...where it should be...
:user_name => "railscasts@railscasts.com".
Agreed. I had to make the same change to get it to work. Thanks!
Thanks for this Dave, I had a hard time tracking this problem down until I found your comment.
Hi!... I'm using ubuntu. After trying this casts. When i run the server, this is the output:
rails s
=> Booting WEBrick
=> Rails 3.0.0.rc application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/israel/Desktop/projects/mailit/config/initializers/setup_mail.rb:12: uninitialized constant DevelopmentMailInterceptor (NameError)
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/engine.rb:201
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/engine.rb:200:in `each'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/engine.rb:200
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/initializable.rb:25:in `instance_exec'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/initializable.rb:25:in `run'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/initializable.rb:50:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/initializable.rb:49:in `each'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/initializable.rb:49:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/application.rb:134:in `initialize!'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/application.rb:77:in `send'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.rc/lib/rails/application.rb:77:in `method_missing'
from /home/israel/Desktop/projects/mailit/config/environment.rb:5
from /home/israel/Desktop/projects/mailit/config.ru:5:in `require'
from /home/israel/Desktop/projects/mailit/config.ru:5
from /usr/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
from /usr/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
from /home/israel/Desktop/projects/mailit/config.ru:1:in `new'
from /home/israel/Desktop/projects/mailit/config.ru:1
Im new in Rails.
Dont know how to solve this...
@Israel B., try posting your issue on railsforum.com along with your source code of setup_mail.rb
One of the best Rails resources around!
I had a problem getting an e-mail to send until I changed:
:port => 587
to
:port => "587"
Thanks Ryan!
Actually, that is not a real issue, so apparently I don't know what I did to resolve my issue.
In all likelihood it was the timing of when I restarted WEBrick that made me think that was it :)
Note, you need to set config.action_mailer.delivery_method=:smtp
otherwise it will silently "work" in dev and test mode but never actually send email (as the default seems to be :test)
This was what I needed to do to fix my issue. Thanks.
One suggest is to add user and password as env variable
$ export GMAIL_USER=email@email.com
$ export GMAIL_PASSWORD=password
$ export MY_DOMAIN=pablocantero.com
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => ENV['MY_DOMAIN'],
:user_name => ENV['GMAIL_USER'],
:password => ENV['GMAIL_PASSWORD'],
:authentication => 'plain',
:enable_starttls_auto => true
}
If you are using heroku
$ heroku config:add GMAIL_USER=email@email.com
$ heroku config:add GMAIL_PASSWORD=password
$ heroku config:add MY_DOMAIN=pablocantero.com
but I didn't work.
i'm having problems with this code,
i'm getting Errno::ECONNREFUSED in UsersController#create
more precisely Connection refused - connect(2) exactly in the delivery line
and i dont now how to fix it...
anyone now?
by the way your site is amazing...
I realize this is 2 years (over) ago, but I thought I'd say I have the same problem. I found there was no .gitignore file so I created it with the README details, with no luck in an app I was working with called launchpage-rails. Seems to be a lack of config for the app.
Just an update - the issue appeared to be that the SMTP was not set up correctly. To rectify: you'll need to ensure your gem mail is set in your Gemfile. Next, create a setup_mail.rb file in config/initializers.
Change to your smtp of choice. Next include in your
And then... magic.
if you are stuck with "uninitialized constant UsersController::UserMailer" error try adding this to the initalizer :
require "development_mail_interceptor"
and don't forget to change :
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
require 'development_mail_interceptor'
How easy or difficult would it be to work this into a user account activation/verification email as well as password resets?
In case anyone else is having problems getting this to work with gmail apps, there is a little error in Ryan's demo code. In mail_setup.rb, user_name must be fully qualified, as in user@domain.tld, not just user. In the example, Ryan has
:user_name => "railscasts"
...where it should be...
:user_name => "railscasts@railscasts.com".
Even I have the same doubt
Hello, I'm using an interceptor to the User when registering on my site it receives a confirmation e-mail and I also know that a User has been registered .. S'p that only I am getting the mail, the User does not receive ...
Can anyone help me?
app/controllers/contatos_controller.rb
view plaincopy to clipboardprint?
ContatoMailer.contato_confirmation(@contato).deliver
no meu
config/initializers/setup_mail.rb
view plaincopy to clipboardprint?
require 'development_mail_interceptor'
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "localhost:3000",
:user_name => "usuario",
:password => "secret",
:authentication => "plain",
:enable_starttls_auto => true
}
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
no meu
lib/development_mail_interceptor.rb
view plaincopy to clipboardprint?
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.subject = "#{message.to} #{message.subject}"
message.to = "admin@admin.com"
end
end
no meu app/mailers/contato_mailer.rb
view plaincopy to clipboardprint?
class ContatoMailer < ActionMailer::Base
default :from => "admin@admin.com"
def contato_confirmation(contato)
@contato = contato
mail(:to => "#{contato.nome} <#{contato.email}>", :subject => "Confirma
I went through this tutorial on a new app with Rails 3.1.1 and it worked perfectly. However, I am now trying to use this on an existing app using Rails 3.0.9 with ActionMailer and DEVISE, and it does not work. I am pretty confident DEVISE uses ActionMailer based on the settings, but whenever I send an email to another use, they get the email and not me.
Has anyone been able to get this to work with DEVISE?
"rails mailit" don't work, is that "rails new mailit"
Hmm...not getting anything. Is there a way to see output of what ActionMailer is doing?
I'm using Rails 3.1 and following http://guides.rubyonrails.org/action_mailer_basics.html
Hey Ryan,
First of all nice tutorial. Can you suggest me a way to develop a web based email client that would fetch mail from a domain using pop/imap.
If anybody else have some idea please suggest.
Thanks,
Souvik
Hi guys!
My problem is that I tried everything from your comments to make emails being sended but nothing works.
WebBrick says that email was sent, so what can be wrong?
Nvm... I should have been reading better!
Thanks for all of the awesome tutorials Ryan!!! I'm a total Rails/coding newbie and I managed to build a directory of printers for my IT dept with your help :). Now I followed this tutorial to try and get emails sent via a Gmail account to a list address (newprinter@domain.org) whenever a new printer is added to the directory. However, I'm stumped as to how to get this working with my rails app and I hope you or someone else can help. Please be gentle with me :). My app is a little different from your example code as I don't require a user registration, it's just a simple directory listing printers (make, model, IP address, IP address, etc.), and people can add/edit/delete printers from the "directory". I am including code from my app which I think is relevant below, although I could be wrong :). There's probably something horribly obvious to you or others which I am not seeing or able to figure out. I'd appreciate any help in advice on getting this working. Or if I should be going a different route to send the emails, please let me know.
TIA,
Mark
Sample from my setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "mail.gmail.com",
:user_name => "myitdept@gmail.com",
:password => "secret",
:authentication => "plain",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "localhost:80"
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
~
Sample from my notifier.rb
class Notifier < ActionMailer::Base
default :from => "myitdept@gmail.com"
def newprinter_notification(list)
@list = "newprinter@domain.org"
mail(:to => @list, :subject => "New Printer Added to Directory")
end
end
~
Sample from my printers_controller.rb
def create
@printer = Printer.new(params[:printer])
end
~
Hey 0ptimus - I'd REALLY like to see this app, I've been trying to get a similar type of app working..
Can you share some/all on github?
Feel free to email me - info on github..
--- EDIT ---
now that I'm re-reading this, maybe you didn't mean directory as "Active Directory"
I'm looking to integrate to AD to automatically notice new objects like printers and build a dashboard..
Troy, yeah, it's just an updatable list of printers. Not doing it in Active Directory. Hopefully someone can help with my issues :)!
In Rails 4 you have to add:
config.autoload_paths += %W(#{config.root}/lib)
to the application.rb file in order to avoid an error when using the interceptor.
Thanks Ryan!
I just set it up for ROR 4 and this link helped me:
http://stackoverflow.com/questions/20769589/actionmailer-not-sending-mail-in-development-rails-4