I'm trying to get sendgrid running on my Rails 3 App with Devise, so devise can send out registration emails etc..
I added the following, config/setup_mail.rb:
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => '25',
:domain => "XXXXXXXXX.com",
:authentication => :plain,
:user_name => "XXXXXXXXXXX#gmail.com",
:password => "XXXXXXXXXX"
}
Shouldn't that be enough for Rails + Devise to send out registration emails? Or do I need something else or a gem of some kind?
The logs show the email being generated but I don't see anything in the log about MAIL being sent successfully or erroring. And my sendgrid account still says 0/200 emails sent.
Is there a better way in Rails to see what's going on when it trys to send the email?
Thanks
You can erase the setup that you have.
heroku addons:create sendgrid:free
That is the only pieces of code you need to get email configured with heroku.
Make sure you have your host link setup which I think you did because it will cause it to crash but if you haven't:
config.action_mailer.default_url_options = { :host => 'myapp.heroku.com' }
Actually this last lien is different on rails3 so watch out for that :)
The "config" line needs to be added to your "production.rb" file.
I'm searching for the same answer myself. In intializers/devise.rb I read:
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
I wonder if Devise has to be told to use Actionmailer.
Related
I want to send emails with sendgrids API from a google cloud platform instance. They have a short tutorial on how to do this but it has the email message, who its from, who to send to, and other info all in app.rb which isnt the normal way messages are sent in rails apps.
I looked at the sendgrid ruby docs and they also dont have very good information. All the info in in one place and they dont state what files to put them in or even mention any smtp settings to use.
Here is what I have so far
development.rb
config.action_mailer.delivery_method = :smtp
# SMTP settings
config.action_mailer.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 465,
:domain => "mydomain.com",
:user_name => ENV['sendgrid_username'],
:password => ENV['sendgrid_password'],
:authentication => :plain,
:ssl => true,
:enable_starttls_auto => true
}
gemfile
gem "sendgrid-ruby"
The email views are in app/views, the mailer methods are in app/mailer the same as normal rails 4 apps have it setup.
So I guess here are my main questions:
Where do I call the environment variables holding the sendgrid api key?
Where do I tell Action Mailer to use sendgrid or SendGrid::Mail as I've seen in a couple of places?
Do I even need the sendgrid gem?
Are the smtp settings correct for sending over SSL with sendgrid?
I'm new to sending emails like this in a rails app and would really appreciate the help.
Put apikey as the name and the actual apikey as password:
config.action_mailer.smtp_settings = {
address: "smtp.sendgrid.net",
port: 587,
domain: "yourwebsite.com",
authentication: :plain,
user_name: 'apikey',
password: Rails.application.secrets.sendgrid_api_key
}
Source
Use Figaro gem: https://github.com/laserlemon/figaro
It will generate an application.yml file for you, where you can store your sendgrid_username and sendgrid_password.
Have you generated your mailer? For example, generate mailer user_notifier where you can define your a default-from email, and some methods like this:
r
# send a signup email to the user, pass in the user object that contains the
user email address
default :from => 'hello#yourdomain.com'
def send_signup_email(user)
#user = user
mail( :to => #user.email,
:subject => 'Thanks for signing up!'
)
end
No, you don't need it.
https://sendgrid.com/docs/Classroom/Basics/Email_Infrastructure/smtp_ports.html
I am stuck with sending emails in Rails. I need to send password reset or activation account emails using Devise gem. Thanks Devise has email sending functionality builtin. I only need to configure sender. I have googled and found many tutorials on how to do that. Here are the things I still don't understand as many tutorials do not talk about them much:
Any tutorial comes with something like that:
config.action_mailer.default_url_options = { :host => 'gmail.com' }
config.active_support.deprecation = :notify
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
# SMTP settings
ActionMailer::Base.smtp_settings = {
:port => 587,
:address => 'smtp.gmail.com',
:domain => 'gmail.com',
:user_name => ENV['username'],
:password => ENV['password'],
:authentication => :plain,
}
So unclear things for me are:
1) what is :host, can I use localhost?, in example it is gmail.com. Do I need to set up some gmail server or whatever.
2) what is :domain, again is it my site domain? or using just gmail.com is fine?
3) What is user_name and password?
So the general question is do I need to install some server for mail on my production server and so on, people on this tutorials skip this part. Who sends my email? Rails app server? or separate smtp server?
1) host is a variable used to generate links to your site in the email (see comment).
2) domain is the sending domain of the email, if you have your own domain you could put your domain there.
3) user name and password are the credentials of your gmail account (or the account that you send mails from). If you have your own smtp relay server set up you can use information for that.
This will likely only work for a minimal number of emails sent, you need to look into a professional service that delivers your emails if you intend on sending more than about 100 per month.
I'm using Rails 4 and Devise 3. I need to send confirmation e-mails for production. These are the SMTP configs for my config/environments/production.rb
config.action_mailer.default_url_options = { :host => 'smtp.gmail.com' }
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:tls => true,
:port => '587',
:user_name => 'my_email#gmail.com',
:password => 'my_password',
:authentication => 'plain',
:enable_starttls_auto => true
}
Logs say that the e-mail's been sent. However, I don't see anything in the inbox. (yes, mailcatcher is off)
Another question, do the configs of the development file affect the production's environment's in any ways? They shouldn't, correct?
Another important question: Using the way above, how many e-mails can be handled? For an example, if I used a third party say, Mandrill, would be better because up for tens of thousands of e-mails can be handled. What about this way?
P.S I've already tried Mandrill and it worked just fine. I am requested not to use a third party though so I won't be able to use Mandrill.
Lastly, is there any other way of sending the confirmation e-mails from the Rails Devise that I'm unaware of yet? Or are there any other configurations that I need to do OUTSIDE OF RAILS to make this work since I won't be using a third party?
Please make sure you have enter correct host name .
config.action_mailer.default_url_options = { :host => 'your domain name' }
As Rails configuration standard if your application running on local machine it loads development env. file settings, if it is production then it load production env. file settings.
I prefer to use sendgrid or Mandrill by MailChimp, if you ave large application then it is better to use 3rd party addons, for small application you can use Gmail .
hope this will help you :)
Im doing a ruby on rails project for work and they would like to use sendgrid, but they also like gmail. With gmail it allows you to send an email from the web browser under a different alias but now also supports sending that through another smtp server instead of their own.
I was wondering if then, it would be possible to send an email from the RoR project through to gmail (so management gets to keep their nice interface and sent box), but then it would forward it through to the sendgrid SMTP servers. Just to clarify I know how to and currently can send an email through gmail as a different alias, but this is specifically to forward it through to sendgrid after it gets to gmail.
I currently have a standard setup of:
Myapp::Application.configure do
config.action_mailer.default_url_options = { :host => 'www.mygenericwebsite.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:tls => true,
:authentication => :plain,
:domain => 'mygenericwebsite.com',
:user_name => "user#mygenericwebsite.com",
:password => "pA55w0RD"
}
class UserMailer < ActionMailer::Base
default :from => "HappyAdmin <user#mygenericwebsite.com>"
You could send via Sendgrid and BCC the Gmail address in your emails, and then apply a label to emails from the app based on the From address. Not sure if you can apply the Sent label, but another label would probably be all right. I think this would be simpler and more robust than sending each email twice.
Just wanted to point out that our product, PostageApp, will allow you to send via the Google SMTP if you are so inclined. All you have to do is add the SMTP details to your project and you're good to go.
I just checked with the personal project I have hooked up with Postage and all the emails sent out appear in the Sent Mail folder.
Let me know if that's what you're looking for, or if you have any other questions!
I am on heroku so am not clear where and how to set it up so that devise can send out emails.
I actually have two directions to go:
I am using sendgrid, so am wondering how it works with that.
For my hand-rolled mailers, I use PostageApp, which I'd prefer because it allows me to see what's going on with my email. The way I use PostageApp is my Mailers are a class of PostageApp's mailer.
Thanks.
In Rails 3 I used the following settings in config/environments/production.rb
# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => '##YOUR_PROJECTNAME##.heroku.com' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 25,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => ENV['SENDGRID_DOMAIN'],
:authentication => :plain
}
Note: you'll need to substitute in your project name - but all those ENV variables are populated for you automatically by heroku.
I just wanted to let you guys know that with the help of one of our customers, we have been able to add integration instructions for Devise with Postage to our documentation. He has also told us that he is updating the code to work with the newer, modularized version of Devise, and he will give us the code as soon as it is ready.