in my Mailgun settings I have 2 domains: sandbox and empresas.xxx.es.
In my production.rb file, I've got it configured as shown:
ActionMailer::Base.smtp_settings = {
:port => ENV['MAILGUN_SMTP_PORT'],
:address => ENV['MAILGUN_SMTP_SERVER'],
:user_name => ENV['MAILGUN_SMTP_LOGIN'],
:password => ENV['MAILGUN_SMTP_PASSWORD'],
:domain => 'empresas.xxx.es',
:authentication => :plain,
}
ActionMailer::Base.delivery_method = :smtp
In my mailer:
class AdminMailer < Devise::Mailer
default from: 'notificaciones#xxx.pro'
layout 'mailer'
def new_user_notification(email)
#email = email
mail(to: 'enrique#xxx.es, nacho#xxx.es, hola#xxx.es', subject: 'Nuevo usuario registrado')
end
end
The 3 emails in the mailer are verified and confirmed in Mailgun
I'm getting the error when sending emails:
Net::SMTPUnknownError (could not get 3xx (421: 421 Domain sandboxde00000.mailgun.org is not allowed to send: Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings.
Related
I'm trying to send an email when a new English-Grade is created in my rails app. In this app it may be relevant that Student is an inherited (STI) type of devise User and I'm trying to send them an email when a teacher (another type of inherited devise User) creates a grade.
At the moment just trying to get it to work locally using gmail. I used
rails g mailer UserMailer
to setup.
This is the error I get when I create an English-grade.
Net::SMTPAuthenticationError in EnglishGradesController#create
530-5.5.1 Authentication Required. Learn more at
#student = Student.find_by_id(#english_grade.student_id)
if #english_grade.save
**UserMailer.new_grade(#student).deliver**
redirect_to(student_path(#student), :notice => "Post was successfully created.")
else // etc
(** is the highlighted error)
The above is also where I'm calling the mailer so I won't repeat it.
My development.rb file:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "my ip address" }
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:domain => 'my ip address:3000', //where 3000 is the port I'm running on locally
:port => 587,
:user_name => ENV['example#gmail.com'],
:password => ENV['password'],
:authentication => "plain",
:enable_starttls_auto => true
}
config.action_mailer.perform_caching = false
My mailer:
class UserMailer < ApplicationMailer
default from: "example#gmail.com"
def new_grade(user)
#user = user
mail to: #user.email, subject: "New grade created"
end
end
From reading some of the other Qs:
In the development.rb I have tried without the 'domain:' and without having the host IP address stuff
I have tried:
http://www.google.com/accounts/DisplayUnlockCaptcha
I have also allowed access for less secure apps https://www.google.com/settings/security/lesssecureapps
I have changed my password to something complicated
I also tried changing port to 465 but got an end of file error.
Also if it's of any relevance I created this gmail account today specifically to send emails for the app
Any help would be greatly appreciated, thanks!
The problem was actually that
:authentication => "plain",
needed to be:
:authentication => "login",
This code fails to send email (nothing happens at all - no error either). What am I doing wrong?
/app/mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default from: "sample#gmail.com"
def email_test()
#user = 'recipient#gmail.com'
mail(to: #user, subject: 'Welcome to My Awesome Site')
end
end
/config/development.rb:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: 'no-reply#example.com'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :login,
:user_name => "sample#gmail.com",
:password => "password123",
}
I invoke the code in folder /app/mailers/. Here I run:
rails runner UserMailer.email_test
Is it because I am putting the gmail smtp settings in development.rb, but am running this code in command line?
I've already turned on 'access to less secure apps' in my gmail account. So confused, please advise thanks!
For Rails 3:
rails runner "UserMailer.email_test.deliver"
For Rails 4:
bin/rails runner "UserMailer.email_test.deliver_now"
I am fighting with setting up the "from" information that is shown in the email in header.
It still shows incorrect email address.
In the mailer class, I manually set the default email address:
class NotificationMailer < ActionMailer::Base
default content_type: "text/html", :from => 'default#email.com'
I also specified this in the method for sending the email(s):
def welcome_email(user)
#user = user
mail(to: #user.email, subject: "Welcome!", from: 'default#email.com')
end
But when I receive this email, it's from my-personal-email#gmail.com. I searched through the Rails app where is this email address set up and it's here:
config/initializers/setup_email.rb:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "logistadvise.com",
:user_name => "my-personal-email#gmail.com",
:password => "mypassword",
:authentication => "plain",
:enable_starttls_auto => true
}
Emails are sent out well, but worries me that I am unable to properly set the "from" header.
How to do that?
Thank you.
Hi I am having a very strange problem. I setup mandrill as per the docs and I am now unable to send mail via my controller. Even devise mails do not seem to be going.... But I am able to send it via the console!
My Mail Config
config.action_mailer.default_url_options = { :host => 'smtp.mandrillapp.com' }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:enable_starttls_auto => true,
:user_name => ENV["MANDRILL_USERNAME"],
:password => ENV["MANDRILL_APIKEY"],
:authentication => 'plain',
:domain => 'yim.mydomain.org',
}
My Mailer
class YimMailer < ActionMailer::Base
default from: "notifier#yim.mydomain.org"
def welcome_email(user, data)
#user = user
#data = data
mail(to: #user.email, subject: 'Welcome!')
end
end
In my controller:
YimMailer.welcome_email(current_user, dummydata).deliver
When i execute the same line via the console, it delivers. What could be the issue?
I am using rails 4
I had the same issue and restarted the server (accidentally), it started working via controller too!
I am trying to get the emails I send through Gmail from my Ruby on Rails app to be from Ben.
Currently when the email arrives in a (seperate, non-related) Gmail account, in the Inbox it has ben in the from section.
Here are my settings:
setup_mail.rb
# my domain is my_example.com, and the email address I am sending from is ben#my_example.com
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "my_example.com",
:user_name => "ben#my_example.com",
:password => "my_password",
:authentication => "plain",
:enable_starttls_auto => true
}
if Rails.env.development?
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
else
ActionMailer::Base.default_url_options[:host] = "my_example.com"
end
report_mailer.rb
def send_notification_email(notification_details)
subject = "testing_email"
mail(:to => notification_details[:email], :subject => subject, :from => "Ben")
end
And here are the email settings in Gmail:
In the :from part you can actually specify the email address this way :
:from => 'Ben <ben#my_example.com>'
The :from key there is actually the email you're sending it from. GMail does not allow this to be overriden, as it can lead to abuse.