I have tried to configure like the tutorials but still can not send email. At the console, it displays the image below:
I have configured in config file \ environments \ development.rb and production.rb as follows:
config.active_record.dump_schema_after_migration = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'gmail username',
password: 'password',
authentication: 'plain',
enable_starttls_auto: true }
app\mailers\user_mailer.rb:
class UserMailer < ApplicationMailer
def registration_confirmation(user)
mail(:to => user.email,:subject => "registered")
end
end
app\mailers\application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: "testonebig#gmail.com"
layout 'mailer'
end
app\controllers\users_controller.rb
def create
#user = User.new(user_params)
UserMailer.registration_confirmation(#user).deliver
respond_to do |format|
if #user.save
format.html { redirect_to #user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: #user }
else
format.html { render :new }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
It runs without any mistakes have been displayed but when I checked gmail, it's not receive any mail.
Are you providing the correct email and password in your development.rb file?
One more thing:
You are sending email from this id "testonebig#gmail.com", please login with this email in gmail. Just to make sure that everything is ok with your account. May be some kind of issue in authentication with your account.
Related
I'm getting ArgumentError SMTP "To address" may not be blank from the Mailer that I created for the test.
My code is almost same with an example in the Rails Guide that you can find in here:
https://guides.rubyonrails.org/action_mailer_basics.html
Or Ruby on Rails tutorial:
https://3rd-edition.railstutorial.org/book/account_activation_password_reset#sec-account_activation_mailer
Server log
Error performing ActionMailer::MailDeliveryJob (Job ID: fa1eac9b-a2e0-4b4b-aca7-c785141fd7ce) from Async(mailers) in 214.6ms: ArgumentError (SMTP To address may not be blank: []):
My Code
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'sendish.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
# app/mailers/appliction_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: 'from#example.com'
layout 'mailer'
end
# app/mailer/user_mailer.rb
class UserMailer < ApplicationMailer
default from: 'notifications#example.com'
def welcome_email(user)
#user = user
#url = 'http://example.com/login'
attachments.inline['helloworld.gif'] = File.read(Rails.root + 'public/helloworld.gif')
mail to: user.email, subject: 'Welcome to My Awesome Site'
end
end
# app/controllers/users_controller.rb
# POST /users.json
def create
#user = User.new(user_params)
respond_to do |format|
if #user.save
# Tell the UserMailer to send a welcome email after save
UserMailer.welcome_email(#user).deliver_now
format.html { redirect_to #user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: #user }
else
format.html { render :new }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
def user_params
params.require(:user).permit(:name, :email, :login)
end
I see Mailer is passing To address in my development
UserMailer#welcome_email: processed outbound mail in 26.0ms
Date: Thu, 10 Sep 2020 15:01:52 -0700
From: notifications#example.com
To: user#example.com
Subject: Welcome to My Awesome Site
Addtional Information
The issue is happening in Heroku production
I set up ActionMailer on an example rails app and action-mailer seems to not be delivering emails.
It's a fairly simple setup, when a user creates an account, they automatically receive a welcome email from the site!
production.rb
config.action_mailer.delivery_method = :smtp
# SMTP settings for gmail
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => ENV['gmail_username'],
:password => ENV['gmail_password'],
:authentication => "plain",
:enable_starttls_auto => true
}
config.action_mailer.raise_delivery_errors = true
user_controller.rb
def create
#user = User.new(user_params)
respond_to do |format|
if #user.save
# Sends email to user when user is created.
ExampleMailer.sample_email(#user).deliver
format.html { redirect_to #user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: #user }
else
format.html { render :new }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
My gmail username and password are successfully set using Figaro.
Also, my Gmail settings are set to allow less secure apps.
What's going on here?
I am trying implementing send mail through action mailer in rails related code are..
my mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "debasish#thejaingroup.com"
def registration_confirmation(user)
mail(:to=>user.email, :subject =>"Registered")
end
end
users.controller is
def create
#user = User.new(user_params)
respond_to do |format|
if #user.save
UserMailer.registration_confirmation(#user).deliver
format.html { redirect_to #user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: #user }
else
format.html { render :new }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
Here, Your initializer\setup_mail.rb setting will go to the development.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 9292 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address =>"smtp.thejaingroup.com",
:domain =>"thejaingroup.com",
:port => 587,
:user_name =>"debasish#thejaingroup.com",
:password =>"************"
:authentication =>"plain"
}
and my view is .. user_registration.text.erb ---is
Hi sir you successfully Completed signed..........!
my have a error msg after running this apps..
SocketError in UsersController#create
getaddrinfo: The requested name is valid, but no data of the requested type was found.
I don't think the address you've used here 'smtp.thejaingroup.com' is the address of the valid email service provider. If you are trying to use your gmail, then it should be 'smtp.gmail.com'.
This is the normal gmail configuration.
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => ENV['gmail_username'],
:password => ENV['gmail_password'],
:authentication => "plain",
:enable_starttls_auto => true
}
In this case, all the mails would be delivered to your gmail. . If you don't want this to happen, you can try the gem letter_opener for development environment. For production env, you may have to use email provider such as mandrill or sendgrid.
I looked at other Action Mailer answers on here and none of the solutions seemed to resolve the issue.
I am trying to implement the Action Mailer shown here, but it is not working for me at all. I am using a FB login to gather the users information, and then using a find_or_create option to update the user.
user = User.find_or_create_by(fb_id: profile_hash["id"])
user.update(sanitized_hash)
user.save
log_in user
redirect_to current_user_profession(user)
In the users controller, I am calling on the mail method on the save method. But for some reason it is not sending out the email once a user instance is saved.
def create
#user = User.new(user_params)
#image = Image.new
respond_to do |format|
if #user.save
UserMailer.welcome_email(#user).deliver
log_in #user
format.html { redirect_to "/talent", notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: #user }
else
format.html { render :new }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
I am sure I have all the coding correct, but for some reason it does not send out a welcome email. From my understanding I am using my personal gmail account credentials, with my username and password, which seemed odd to me, but I did it anyways.
Here is my development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = {:host => 'localhost:3000'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV['GMAIL_USER_NAME'],
password: ENV['GMAIL_PASSWORD']
}
The actual email to be sent
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="styles/style.css"/>
</head>
<body>
<h1>Hey <%= #user.name %>,</h1>
<p>Welcome to the site!</p>
<p>To login to the site just click on this link <%= #url %></p>
</body>
</html>
And the user_mailer.rb file.
class UserMailer < ApplicationMailer
default from: "support#mystyleblox.com"
def welcome_email(user)
#user = user
#url = 'http://www.mystyleblox.com'
mail(to:#user.email, subject:'test welcome email')
end
end
Any help would be appreciated, and also if someone could explain the development.rb file and what it needs for the gmail access, is this my personal account, or is this something I had to do separately from my personal account. Thanks in advance.
To eliminate a possible source of the issue, it may well be worth hard-coding your gmail username and password - again, just as a test - so that it's not an issue with the loading of the ENV vars.
I use Rails.application.secrets.domain_name for hiding my super-secret awesome domains but before I get there, I typically use hard-coded values, etc. One thing I noticed between your and my local setup is the domain. My domain is not gmail.com; rather, it's the actual domain of my app.
Locally in my app, I have the following which works for my local server sending emails.
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: 'my domain',
authentication: "plain",
enable_starttls_auto: true,
user_name: 'my email address',
password: 'mypass'
}
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
# Send email in development mode?
config.action_mailer.perform_deliveries = true
Just a thought ...
I have an app where when users register they get a confirmation email set to them.
here's the users controller create action:
def create
#user = User.new(params[:user])
respond_to do |format|
if #user.save
UserMailer.registration_confirmation(#user).deliver
log_in(#user)
format.html { redirect_to #user, notice: "Welcome to Pholder, #{#user.name}!" }
format.json { render json: #user, status: :created, location: #user }
else
format.html { render action: 'new' }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
as you can see after #user.save there is a mailer. However, a person just told me he got an error ("we're sorry, something went wrong") on heroku after trying to register, so I tried it myself and also got an error
2012-11-16T17:21:28+00:00 app[web.1]: Net::SMTPAuthenticationError (535-5.7.1 Please log in with your web browser and then try again. Learn more at
2012-11-16T17:21:28+00:00 app[web.1]: ):
after looking around my code, I tried making another user but this time it worked. Does anyone know why? I read in another post that this could be because it'll fail if too many users register at once (since too many emails are sent), but I don't think anyone was registering at that point since not many people know about my app.
smtp settings:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'pacific-ravine-3563.herokuapp.com',
:user_name => ENV["EMAIL"],
:password => ENV["PASSWORD"],
:authentication => "plain",
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = { :host => 'pacific-ravine-3563.herokuapp.com' }
Google might be blocking you until you prove you’re human. Try logging in to this Gmail account through a web browser. If it doesn’t work then, try visiting this link while logged in and completing the test.
If it helps anyone, I had to go here and "recognize" the activity as my own (it was coming from a server hosted by Heroku): https://security.google.com/settings/security/activity