I built an example app to try to make the mailer work. The app is hosted on https://blooming-brushlands-80122.herokuapp.com,
and the source code is here. Here's my config associated with action mailer:
config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: 'no-reply#example.com'}
and for sending the mailer
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
end
The app does not send emails to users.
Does anyone have any idea why?
This answer assumes you're using the free sendgrid Addon from Heroku since I see you're using sendmail. To add it just log into heroku and add it as a free resource. Since you didn't specify whether or not your trying to send emails locally or in production I added configs for both. In your config/environment/development.rb file you should do the following to send from your local:
config.action_mailer.delivery_method = :smtp #Yours used sendmail, change to this.
config.action_mailer.perform_deliveries = true #Needed if this is dev env. file
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['KUNZIG_SENDGRID_USERNAME'],
:password => ENV['KUNZIG_SENDGRID_PASSWORD'],
:domain => 'localhost:3000',
:enable_starttls_auto => true
}
Obviously replace the username and password with your own env. variables assigned by Heroku. Heroku's config. vars can be found under the settings tab. just click the "reveal" button.
Your environment/production.rb file would be something like:
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'kunzig.herokuapp.com',
:enable_starttls_auto => true
}
Notice the only change is the domain name and environment variables since these are set automatically by Heroku when you add Sengrid as an addon. Also, change your deliver call in your controller to deliver_now so we know it's not a problem with your background worker config.
Related
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.
Hi I'm trying to create simple app. After devise user is logged in can create event as soon as create this email will be send to him.
def create
#event = Event.new(event_params)
#event.user = current_user
#event.save
#user= current_user
UserMailer.welcome_email(#user).deliver
respond_with(#event)
end
I've change on production and development files
config.action_mailer.default_url_options = { :host => 'https://mydomiantest.io' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:user_name => 'username',
:password => 'mypassword',
:domain => 'mydomiantest.io',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
I've also created user_mailer.rb in mailers
class UserMailer < ActionMailer::Base
default from: 'no-replay#mytestsite.io'
def welcome_email(user)
#user = user
#url = 'mytestsite.io'
mail(to: #user.email, subject: 'Welcome to My Awesome Site')
end
end
It is takes some time after creating event and then I don't have any email, I have created account on site grid what else do I need to do?
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
Ok, i'm a total newbie so please forgive me in advance.
I want to create a very simple rails application. I've created a button that's supposed to send an email to myself. I've had no previous Rails experience so any help you can give is much appreciated.
Here's what I've done so far:
config/environment.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'baci.lindsaar.net',
:user_name => 'myUsernameHere',
:password => 'myPassHere',
:authentication => 'plain',
:enable_starttls_auto => true }
controllers/posts_controller.rb:
def sendMessage
UserMailer.welcome_email().deliver
respond_to do |format|
format.html { render :nothing => true, :status => :ok }
end
end
app/mailers/user_mailer.rb:
class UserMailer < ActionMailer::Base
def welcome_email()
mail(:to => '<my email address here>',
:subject => "Welcome to My Site")
end
end
I've also created the email template in views/user_mailer/welcome_email.html.erb
The problem: I click on the button and I don't receive an email.
Thank you very much in advance.
Matt
In MycontrollerController send_mail is action so this is wrong def send_email(address) just define
def send_email(address)
#address = params[:address]
PostMailer.test_email(#address).deliver
end
I think that is what the above error is
nevermind, i was forgettting
default :from => "<email address here>"
in app/mailers/user_mailer.rb
it works now.