Emails are not sent to addresses except verified addresses (Mailgun and Heroku) - ruby-on-rails

I'm building a web app with Rails.
In the production environment, I want to use Mailgun to send account verification emails, but when I register with an address other than the ones I've authenticated and I am using for Heroku, I get the following error and can't send the emails.
Net::SMTPUnknownError (could not get 3xx (421: 421 Domain sandbox3fb706e74ad5432f99a8627384de2867.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.
Here is my production.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'protected-island-35085.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
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 => host,
:authentication => :plain,
}
I'm having trouble with this because I can't send emails to users after releasing the application.
The idea that Email cannot be sent to not-verified address if I use free-plan of Mailgun has come up to me, is that right?
How can I make it so that I can send emails to other addresses properly?
Also, if there is any missing information, please let me know and I will add it.

Related

Rails: Send emails from namecheap email address

I'm getting the following error when trying to send an email notification:
Connection refused - connect(2) for "mail.privateemail.com" port 25
I'm in development mode and this is the setup I have:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'mail.privateemail.com',
:port => 25,
:user_name => 'my_email_address_here',
:password => 'password_here',
:authentication => :plain,
:enable_starttls_auto => true }
Any idea what I might be doing wrong here?
Namecheap uses ports 465 for SSL, and 25/587 for TLS/STARTTLS. Additional to this, you must disable SPA in the Namecheap dashboard in order to send emails outside of their dashboard. So I would say all you need to do is disable SPA from the dashboard and you'll be good to go.
As a side note, be sure to store your email address and password in environment variables to keep your credentials out of any version control you may be using.

Configuring production.rb file to send emails with Rails 4

I am stuck with sending emails in Rails. I need to send password reset or activation account emails using Devise gem. Thanks Devise has email sending functionality builtin. I only need to configure sender. I have googled and found many tutorials on how to do that. Here are the things I still don't understand as many tutorials do not talk about them much:
Any tutorial comes with something like that:
config.action_mailer.default_url_options = { :host => 'gmail.com' }
config.active_support.deprecation = :notify
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
# SMTP settings
ActionMailer::Base.smtp_settings = {
:port => 587,
:address => 'smtp.gmail.com',
:domain => 'gmail.com',
:user_name => ENV['username'],
:password => ENV['password'],
:authentication => :plain,
}
So unclear things for me are:
1) what is :host, can I use localhost?, in example it is gmail.com. Do I need to set up some gmail server or whatever.
2) what is :domain, again is it my site domain? or using just gmail.com is fine?
3) What is user_name and password?
So the general question is do I need to install some server for mail on my production server and so on, people on this tutorials skip this part. Who sends my email? Rails app server? or separate smtp server?
1) host is a variable used to generate links to your site in the email (see comment).
2) domain is the sending domain of the email, if you have your own domain you could put your domain there.
3) user name and password are the credentials of your gmail account (or the account that you send mails from). If you have your own smtp relay server set up you can use information for that.
This will likely only work for a minimal number of emails sent, you need to look into a professional service that delivers your emails if you intend on sending more than about 100 per month.

Rails 3.2 email sent via smtp is flagged as unencrypted by gmail

I would like to ask what I missed why my email was flagged as unencrypted by Gmail. My project uses Hostmonster.com no-reply account to send email.
Rails smtp settings:
config.action_mailer.default_url_options = { host: APP_CONFIG[:host], port: APP_CONFIG[:port], protocol: "https" }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "host289.hostmonster.com",
:port => 465,
:domain => APP_CONFIG[:smtp][:domain],
:user_name => APP_CONFIG[:smtp][:user_name],
:password => APP_CONFIG[:smtp][:password],
:authentication => "plain",
:enable_starttls_auto => true,
:ssl => true
}
Hostmonster cpanel:
enter image description here
The project is already in HTTPS. I don't know if it's in my end causing the Gmail unencrypted issues or on hostmonster.
enter image description here
I believe this is rather about the configuration of the hosting SMTP server when talking to GMail servers. You are sending your email to the hostmonster SMTP server via encrypted SMTP connection, which is correct. But it's the hostmonster's responsibility to also send the mail encrypted further on, which they probably don't do.
I would contact the hostmonster's support about this issue, i.e. ask them if they use encrypted communication when sending outgoing emails from their servers.

Ruby on Rails ActionMailer SMTP Settings

trying to set up my own ActionMailer::Base in RubyRails -> This works:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "anythingworks",
:user_name => "mygmailaddress#gmail.com",
:password => "somePW",
:authentication => "plain",
:enable_starttls_auto => true
}
fine.. but it would be nice if I could use my mail server. but when i am trying this:
ActionMailer::Base.smtp_settings = {
:address => "smtp.myowndomain.de",
:port => 25, (tried 587) also
:domain => "triedanything",
:user_name => "mycorrectuser",
:password => "yesitisthecorretpw",
:authentication => "plain",
:enable_starttls_auto => true
}
Tried lot of different settings / changes. But no E-Mail is sent. Is there any logs avaiable to this ? Think its something because authentication... "login" instead of "plain" doesnt help...
Had some tests with telnet sending some E-mails from command line.
gmail doesnt work from command line (saying STARTTTLS or something). My own domain mails server (which is hosted from some provider) says "relay access denied" (from commandline).
Webmail both working..
Any ideads ? Thanks!
The answer is the "relay access denied" message. Your smtp server needs to be configured to relay emails for this to work. I suspect that your smtp server is configured to accept connections for delivery TO your domain, not to relay emails elsewhere.
The same error message will probably be found in the smtp server's log files. Try sending an email to yourself (which would just be an accept, rather than a relay, for your smtp server). If emails to yourself are delivered, but emails to other domains are not, you will have confirmation that that is the problem.
Your ISP probably has an smtp server you can use for outgoing emails. If you want to use your own email server, it will need to be configured to relay emails.

send email from localhost

I'm try learn about email in rails. I'm developing something on localhost. Is it possible to send an email from localhost to say a normal mail account like gmail? Do I have a install a mail server? I've just got a standard rails installation at the moment for development.
Update for rails 4.0
Now you need these code to make it work:
# I recommend using this line to show error
config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:domain => 'mail.google.com',
:port => 587,
:user_name => 'foo#gmail.com',
:password => '******',
:authentication => :plain,
:enable_starttls_auto => true
}
You can set up ActionMailer to use Gmail's SMTP server using something like this in config/environment.rb:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = {
:address => 'smtp.gmail.com',
:domain => '<your domain>',
:port => 587,
:user_name => '<your gmail>',
:password => '<your password>',
:authentication => :plain
}
Edit: If you experience any difficulties, set your config to display errors:
ActionMailer::Base.raise_delivery_errors = true
Have a look at ActionMailer. In RAILS_ROOT/config/environment/ , there is a file for different environments (development, test, production) the configurable settings go in these files
You specify the delivery_method like this,
ActionMailer::Base.delivery_method = :sendmail
or if you want
ActionMailer::Base.delivery_method = :smtp
A detailed example of the settings has been posted by Mikael S
HTH
If I understand your situation correctly, you want to send an email from your local computer using a custom email address such as john#mycompany.com. If you already registered the domain name for your email account ( mycompany.com ) is very likely that the company that is hosting your website, also has a POP/SMTP server. If so, you can use Mikael S's sample and change the address parameter to your Hosting company's smtp address and use your hosting company's username/password.
If you have not register your custom domain or don't have a hosting provider, you can install a free email server in your local computer. If you use WindowsXP, you can add the IIS email server by going to add/remove programs->windows features. If you are using Linux, you can use any of the email servers available in the repositories. Once you install your local email server you will use Mikael S's sample code and use 127.0.0.1 or localhost in the address field. If you are using WindowsXP's email server, I think you don't have to enter username/password.
Hope it helps you.
You can send it from localhost, you can even set the sender as a 'real' mailbox e.g. you#gmail.com.
However, some (or say most) servers will not accept this mail as part of their spam blocking strategy (inability to verify the sender identity).
However, In the past, I have had something similar with python which worked on gmail.
so good luck ;-)

Resources