Sending mail for devise - ruby-on-rails

I am trying to send mail through sendgrid from my rails app. I have setup sendgrid previously. I was able to send and receive mail in the development and the production, through heroku. Everything worked for a day. I came back a couple of days later and nothing worked.
There are no errors. In dev it says the mail is sent but the email doesn't send and same for production.
Here is my setup:
development.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
production.rb
config.action_mailer.default_url_options = { host: 'herokuapp.com' }
Rails.application.routes.default_url_options[:host] = 'herokuapp.com'
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
setup_mail.rb
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: 'smtp.sendgrid.net',
port: '587',
:authentication => :plain,
user_name: 'user',
password: 'pass',
domain: 'herokuapp.com',
enable_starttls_auto: true
}
I have tried resetting my pass to sendgrid and removing then re-adding it but then I run into an error saying "user banned" and I am unable to re add it.
I have also tried switching to postmark with similar results where the mail is never received but is sent.

You should check on Sendgrid if they are receiving your email requests.
From the documentation:
Search for the email in Email Activity. If we successfully delivered the message you will see a delivered event with the time of delivery. If you do not see the email come up, you can click on search options and make sure processed and deferred are checked. A processed event indicates that we actually got the request from you. Deferred events show if there are issues or delays with the receiving server accepting the message.

Related

ArgumentError (SMTP-AUTH requested but missing user name)

I am working on a basic app called PhotoApp, where I am learning how to set up SMTP with rails. I have used basic Ruby with SMTP sometime ago, and I know my email works, just the emails sent gets to spam folder.
But when I am trying to configure SMTP on Rails, I am getting ArgumentError (SMTP-AUTH requested but missing user name):, and that's the primary reason why the app, when pushed to heroku, crashed every time a user signs up.
Here's my config/environments/development.rb:
config.action_mailer.default_url_options = { host: 'localhost:8080' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.net',
authentication: 'plain',
enable_starttls_auto: true,
user_name: 'gmail_email',
password: '...'
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
I am running the server on localhost:8080, in development mode, so my host is set to localhost:8080.
Apart from that I am not able to get my app working with my gmail username with SMTP in rails.
Edit, this ruby code works:
#!/usr/bin/ruby -w
require 'net/smtp'
message = <<~EOF
From: mygmail#gmail.com
To: someone#protonmail.com
Subject: Hello!
Hello!
#{"HELLO ".*(50).delete_suffix(?\s)}
EOF
Net::SMTP.new('smtp.gmail.com', 587).tap(&:enable_starttls_auto).start('gmail.com', 'mygmail#gmail.com', 'mygmailpass', :plain) do |smtp|
smtp.send_message message, 'mygmail#gmail.com', 'someone#protonmail.com'
end
But as a newbie to rails, I can't get actionmailer working when the same email is used in the config file...

RefineryCMS inquiries not sending email

I'm working with an old RefineryCMS 1.0.8 project and migrating it to another server. It all works apart from the contact us form.
Here is my setup in the production.rb file
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
config.action_mailer.delivery_method = :sendmail
# Defaults to:
# config.action_mailer.sendmail_settings = {
# location: '/usr/sbin/sendmail',
# arguments: '-i -t'
# }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
if ENV['MAILER_USERNAME'].present? && ENV['MAILER_PASSWORD'].present?
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "my_domain.com.au",
user_name: "#{ENV['MAILER_USERNAME']}",
password: "#{ENV['MAILER_PASSWORD']}",
authentication: 'plain',
enable_starttls_auto: true
}
end
I've set the environment variables in my /etc/environment and /etc/apache2/envvars files like so;
export MAILER_USERNAME="<email address>"
export MAILER_PASSWORD="<password>"
I've also set the tld to a length of 2 as we are in Australia so we are using a .com.au. This is set in my config/application.rb
config.action_dispatch.tld_length = 2
Here is the error I get;
Sent mail to <my gmail address> (2924ms)
There was an error delivering an inquiry confirmation:
555 5.5.2 Syntax error. w20sm33182626pfi.31 - gsmtp
You should wrap your email in <> blocks.
export MAILER_USERNAME="<map#gmail.com>"
export MAILER_PASSWORD="password"
I found the problem was not the brackets around the email it was the fact that I hadn't setup the DNS to that machine yet. Once I did that last night and went to the refinerycms website at it's domain instead of the IP then I could send emails.

How to send emails from Rails 4 with Postfix on production

I know this question is posted already here but all the solutions provided didn't work for me.
I already installed Postfix and tested it successfully with:
date | mail -s test myemail#example.com
My config/environments/production.rb has:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "localhost",
:port => 25,
:domain => "myhost",
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
I even changed :smtp with :sendmail
config.action_mailer.delivery_method = :sendmail
It didn't work as well.
The /var/log/mail.log doesn't show anything my application log as well nothing.
Postfix is up and running fine, any help is much appreciated.
Ps: Is there something I am missing here? I only want to send emails from my app not receive them.

Actionmailer cannot send using Gmail

With the same config/application.rb (see below), I can send with one Gmail account, but not for a second Gmail account. The second Gmail account is preferred, I verified the login credentials with a browser and have ensured it accepts "less secure apps".
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
user_name: 'accountname',
password: 'secret',
authentication: 'plain',
enable_starttls_auto: true
Also with the second Gmail, I got NET::SMTPAUthenticationError in production, and it just does not send in development mode without complaining.
Finally, I am using Rails console, and my objective is to use a rake task to send email instead of in the web environment.

rails, heroku devise action mailer not working - how to debug?

i am trying to set up confirmable with heroku devise for my app. here is my code: (followed a few tutorials)
config.action_mailer.default_url_options = { :host => 'myapp.herokuapp.com' }
Rails.application.routes.default_url_options[:host] = 'myapp.herokuapp.com'
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: ENV["GMAIL_DOMAIN"],
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
i've added the heroku variables for the password/domain/username. but when i try to sign-up on my live site, i get an error.
does anybody see any errors? or can someone point me on how I can debug this? thanks!
Heroku & Gmail have some authentication token problem while sending e-mail.
It is better to use sendgrid or Mandrill by MailChimp
They both are free & configuration is very easy

Resources