I want to use the Mailer of Rails 4 with the Gmail's smtp configuration
In my development file i set:
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "mymail#gmail.com",
:password => "mygmailpassword",
:authentication => :plain,
:enable_starttls_auto => true
}
but i don't recive any mails.
This is the output of the terminal:
To: antonioni.giovanni9#gmail.com
Message-ID: <55ffb56da9e91_aa929362303435c#pc-rails.mail>
Subject: Conferma ordine
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_55ffb56da807b_aa92936230342e1";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_55ffb56da807b_aa92936230342e1
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
so my application try to send an email but this not appear on my gmail dashboard.
Any idea for resolve this trouble?
Gmail smtp service need an APP PASSWORD for send a mail from a gmail account (for more info visit this link). After generating the password you must change the configuration of the development file:
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "mymail#gmail.com",
:password => "GENERATEDPASSWORD",
:authentication => :plain,
:enable_starttls_auto => true
}
And then restart the server.
For catching the error i've set: config.action_mailer.raise_delivery_errors = true (Thanks Dipak for the tip)
You also need to change this: https://www.google.com/settings/security/lesssecureapps
Related
I am using devise for authentication. It provides a forgot password link. When i send email then the email is not sent. Following is the settings i have used. Can you tell me why gmail is not sending the email? I have also turned on "allow less secure app to send email" and i have also enabled imap in gmail setting.
application.rb has the following setting.
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:domain => 'mail.google.com',
:port => 587,
:user_name => 'validemail#gmail.com',
:password => 'validpassword',
:authentication => 'login',
:enable_starttls_auto => true
}
development.rb has
config.action_mailer.default_url_options = { host: '127.0.0.1'}
config.action_mailer.delivery_method = :smtp
After sending the email i get the following text in the console.
Devise::Mailer#reset_password_instructions: processed outbound mail in 215.2ms
Sent mail to validemail#gmail.com (1097.6ms)
Date: Thu, 29 Dec 2016 09:50:41 +0000
From: please-change-me-at-config-initializers-devise#example.com
Reply-To: please-change-me-at-config-initializers-devise#example.com
To: validemail#gmail.com
Message-ID: <5864dc7161acb_173921a07788707d#kofhearts-rubyonrails-3267120.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Hello validemail#gmail.com!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p>Change my password</p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
Redirected to https://rubyonrails-kofhearts.c9users.io/users/sign_in
Completed 302 Found in 1965ms (ActiveRecord: 14.7ms)
UPDATE:
I am just following this tutorial.
https://www.youtube.com/watch?v=ZEk0Jp2dThc
Send email is not working with the settings that are specified in this video.
Enabling less secure apps in my account settings worked for me.
Google Account settings > Signing in to Google > scroll down to the bottom
Turn on allow less secure apps. Try sending the email again.
That's should work.
Maybe you could also turn on config.action_mailer.raise_delivery_errors = true
in config/environments/development.rb.
It's easier to debug.
Maybe you forget to set config.action_mailer.perform_deliveries = true in config/environments/development.rb?
Have you tried this?
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "myinfo#gmail.com",
:password => "secret",
:authentication => "plain"
# :enable_starttls_auto => true # I don't have this, but it should work anyway
}
it it's sent maybe you don't receive it because of the spam filter, first thing to check:
class UserMailer < ActionMailer::Base
default :from => "myinfo#gmail.com"
# ...
end
You also check your Forwarding and POP/IMAP in your gmail..
include these line of codes on your development.rb
config.action_mailer.default_url_options = {host: 'your server' } # ex. localhost:3000
config.action_mailer.raise_delivery_errors = true # to raise error if smtp has error on setup
config.action_mailer.default :charset => "utf-8"
If you are working with Gmail you should activate permission to
externals apps send email through SMTP.
In development mode Rails does not send emails, you should run Rails in production rails s -e production or turn on config.action_mailer.raise_delivery_errors = true
do not forget to use mail().deliver or for Rails 5+ mail().delivery_now
look you this is my SMTP configuration
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => ENV['mailer_address'],
:port => ENV['mailer_port'],
:user_name => ENV['mailer_username'],
:password => ENV['mailer_password'],
:authentication => "plain",
:enable_starttls_auto => true
}
this is my Class Mailer
def send_email
mail(to: "example#email.com", subject: 'not reply this message').deliver
end
I call that function from my controller. If you got any error you should print it to check what is the problem.
begin
myMailer.send_email
rescue Exception => e
flash[:error] = "Imposible sent email, #{e.inspect}"
end
I am facing issue with devise forgot password.I am not receiving any email though devise displays messsage that "you will receive an email with instructions about how to reset your password in a few minutes".
Ruby-1.9.3 Rails 3.2 devise 2.2.4
My environments/development.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain,
:domain => 'xyz#gmail.com',
:user_name => 'xyz#gmail.com',
:password => 'abcde',
}
My environment.rb
ActionMailer::Base.delivery_method = :smtp
My intializers/devise.rb
config.mailer_sender = "xyz#gmail.com"
And development.log shows
Sent mail to xyz#gmail.com (3205ms)
Date: Wed, 26 Jun 2013 23:33:01 +1000
From: xyz#gmail.com
Reply-To: x#gyzmail.com
To: xyz#gmail.com
Message-ID: <51caed8dd99a5_15365823b9268927#nbnco-U01.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Hello xyz#gmail.com!</p>
<p>Someone has requested a link to change your password. You can do this the link below.</p>
<p>Change my password</p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
Redirected to http://localhost:3000/users/sign_in
Completed 302 Found in 3423ms (ActiveRecord: 0.0ms)
As have been mentioned above in development mode mails aren't being send for real, if you're curious how that's obtained (and maybe want to override that behavior) look into the following file
config/environments/development.rb:
#don't send emails in development
config.action_mailer.perform_deliveries = false
Of course it would be better to use some mailtrap but if you want to just quickly see mail in your mailbox just change that false to true and here it goes if you've got properly configured mailer of course.
Edit:
That's my config for gmail and it works, there is no domain param so probably it's making trouble:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => '<login>',
:password => '<password>',
:authentication => 'plain',
:enable_starttls_auto => true }
Edit2: And don't forget to restart your server ;)
In development with your configuration emails are not sent but are just visible in the logs. You can try and use a service such as:
http://mailtrap.io/pages/ruby_landing
https://github.com/ryanb/letter_opener
https://github.com/37signals/mail_view
I tried to configure actionmailer to send via google apps with smtp.
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mydomain.com",
:user_name => "username",
:password => "password",
:authentication => 'plain',
:enable_starttls_auto => true }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
However whenever gitlab tries to send an e-mail:
Sent mail to user#my.domain.com (10ms)
Completed 500 Internal Server Error in 29ms
535-5.7.1 Username and Password not accepted
Server runs ruby 1.9.3p194. Why doesn't google apps accept the username/password?
It works now, I think the problem was with the username. it needs the domain in the username. i.e. the problem was
user_name: 'username'
Whereas the correct way (at least for google apps) is
user_name : 'username#mydomain.com'
this works for me:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "you#gmail.com",
:password => "password",
:authentication => 'plain',
:enable_starttls_auto => true }
Try setting the domain to gmail.com
I created my mail contact formular with this post: link
In the post regards to gmail. I'm from Germany, I could only use googlemail.com instead. So I changed everything from gmail to googlemail. I get no errormessages but no mails are received in the googlemail account.
This is my mailing config:
# Mail config
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.googlemail.com",
:port => 587,
:user_name => 'khsuite#googlemail.com',
:password => 'mypassword',
:authentication => 'plain',
:enable_starttls_auto => true }
Are there any other settings necessary for googlemail?
I am following Ryan Bates's tutorial on Rails 3 ActionMailer. I generate the mailer in terminal and then establish a setup_mail.rb under config/initializers. I keyed in the following code:
ActionMailer::Base.smtp_settings={
:address => "smtp.gmail.com",
:port => 587,
:domail => "gmail.com",
:user_name => "my_account_at_gmail",
:password => "my_password",
:authentication => "plain" ,
:enable_starttls_auto => true
}
My user_mailer.rb file goes like:
class UserMailer < ActionMailer::Base
default :from => "my_account_at_gmail#gmail.com"
def registration_confirmation(user)
mail(:to => user.email,:subject => "registered")
end
end
I tested in rails console:
u=User.first
UserMailer.registration_confirmation(u).deliver
it displays:
#<Mail::Message:2194479560, Multipart: false, Headers: <Date: Sat, 26 Feb 2011 14:42:06 +0800>, <From: my_account_at_gmail#gmail.com>, <To: some_account#gmail.com>, <Message-ID: <some_number#My-MacBook-Pro.local.mail>>, <Subject: registered>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>
BUT I never received the email here... Why? How can I solve this? I guess it is some problem on send_mail.rb file..
If that's a copy/paste of your send_mail.rb, there is a spelling error in :domain (you have :domail) which may or may not be causing the issue.
If that doesn't work, try the following:
ActionMailer::Base.delivery_method = :smtp # be sure to choose SMTP delivery
ActionMailer::Base.smtp_settings = {
:tls => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :plain,
:user_name => "my_account_at_gmail#gmail.com", # use full email address here
:password => "password"
}
Alternatively, it has been been suggested in the Action Mailer Rails Edge Guide
to put the email configuration in the appropriate .rb file in your config/environments directory. For me, I put the following in config/environments/development.rb to get emails sent using gmail's SMTP server:
config.action_mailer.raise_delivery_errors = true #useful to have to debug
config.action_mailer.perform_deliveries = true #default value
config.action_mailer.delivery_method = :smtp #default value
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "yourdomain.com",
:user_name => "username#yourdomain.com",
:password => "yourpassword",
:authentication => :login, #or can use "plain"
:enable_starttls_auto => true
}