ActionMailer and Exchange - ruby-on-rails

I successfully send Mails via SMTP using my Rails App and my Postfix Server. Now I need to move to an Exchange: Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 that has POP3 and SMTP support enabled.
I use actionmailer 1.2.5 and am not able to successfully login to the server while trying to send a mail.
In case I use Mail.app sending and recieving works fine as long as I change the authentication schema to "Password". Checking the server looks like so:
READ Nov 18 10:37:00.509 [kCFStreamSocketSecurityLevelNone] -- host:mail.my-mail-server-domain.com -- port:25 -- socket:0x11895cf20 -- thread:0x11b036a10
250-mail.my-mail-server-domain.com Hello [xxx.xxx.xxx.xxx]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK
WROTE Nov 18 10:37:00.852 [kCFStreamSocketSecurityLevelNone] -- host:mail.my-mail-server-domain.com -- port:25 -- socket:0x11895cf20 -- thread:0x11b036a10
AUTH LOGIN
READ Nov 18 10:37:01.848 [kCFStreamSocketSecurityLevelNone] -- host:mail.my-mail-server-domain.com -- port:25 -- socket:0x11895cf20 -- thread:0x11b036a10
235 2.7.0 Authentication successful.
So authentication method :login seems to be properly supported. Now when it comes to my configuration for actionmailer it looks like so:
ActionMailer::Base.server_settings = {
:address => "mail.my-mail-server-domain.com",
:port => 25,
:domain => "my-mail-server-domain.com",
:authentication => :login,
:user_name => "myusername",
:password => "mypassword"
}
And I get authentication errors over and over. I also tried to change
:user_name => "my-mail-server-domain.com\myusername"
:user_name => "my-mail-server-domain.com\\myusername"
:user_name => "myusername/my-mail-server-domain.com"
:user_name => "myusername#my-mail-server-domain.com"
but nothing works. Can anyone help me?
Regards.
Jason

i think you need to add
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:domain => "my-mail-server-domain.com",
:address => "mail.my-mail-server-domain.com",
:port => 25
:authentication => :login ,
:user_name => 'myusername',
:password => 'mypassword',
}
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.default_content_type = "text/html"
or try changing your port. usually port 25/26 is blocked to send emails, and some email providers are refusing to receive email from port 25 that uses localhost smtp.
Or maybe your internet provider is blocking port 25.
if it still doesn't work you could write the errors here.

Related

Net::SMTPAuthenticationError (504 5.3.3 AUTH mechanism PLAIN not available

I am trying to send emails from my website by using aplus.net
I am getting this error
Net::SMTPAuthenticationError (504 5.3.3 AUTH mechanism PLAIN not available
Here is my configiration
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "mail.aplus.net",
:port => 1025,
:domain => 'www.limoexotic.com',
:user_name => 'booking#limoexotic.com',
:password => 'xxxx',
:authentication => :plain,
:enable_starttls_auto => true
}
In cases like this, you should check with telnet to see which authentication mechanisms are available by the mail server. In this case, mail.aplus.net only allows LOGIN authentication (See AUTH LOGIN below), so changing :plain to :login should make it work.
> $ telnet mail.aplus.net 1025
Trying 64.29.151.235...
Connected to mail.aplus.net.
Escape character is '^]'.
220 mail42c40.carrierzone.com ESMTP Sendmail 8.14.9/8.14.9; Tue, 7 Jul 2020 05:04:56 +0000
EHLO mail.aplus.net
250-mail42c40.carrierzone.com Hello [x.x.x.x], pleased to meet you
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-SIZE 52428800
250-DSN
250-AUTH LOGIN
250-STARTTLS
250-DELIVERBY
250 HELP

Emails send from rails with O365 being rejected as spam

I have a Rails 5 app deployed on Heroku. I'm using devise for email and have setup everything correctly to send password reset emails. This works perfectly in my dev environment. However, when I send from production I get an error in my 0365 inbox that says:
Generating server: CO2PR13MB0140.namprd13.prod.outlook.com
myemail#gmail.com
Remote Server returned '550 5.7.708 Service unavailable. Access denied, traffic
not accepted from this IP. For more information please go to
http://go.microsoft.com/fwlink/?LinkId=526653 AS(8561)
[CO2PR13MB0124.namprd13.prod.outlook.com]'
Original message headers:
Received: from CO2PR13MB0140.namprd13.prod.outlook.com
([fe80::c872:9c6:9d6a:8b3]) by CO2PR13MB0140.namprd13.prod.outlook.com
([fe80::c872:9c6:9d6a:8b3%4]) with mapi id 15.20.1339.019; Wed, 14 Nov 2018
02:42:20 +0000
MIME-Version: 1.0
Content-Type: text/plain
Date: Wed, 14 Nov 2018 02:42:20 +0000
Message-ID:
<5beb8b87e888a_42b06292aba70609bd#01184e4c-2116-478b-a773-fcc26ac206aa.mail>
Subject: Reset password instructions
In looking into this, and talking to support, it appears that the it's being rejected because a third party server is (my app on Heroku I'm assuming) is trying to send out the email with 0365 settings.
Here are my development.rb settings that work perfectly:
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.office365.com',
:port => '587',
:authentication => :login,
:user_name => ENV['365_USERNAME'],
:password => ENV['365_PASSWORD'],
:domain => 'mysite.com',
:enable_starttls_auto => true
}
Here are my production.rb settings that cause O365 to reject the email. I've tried playing with these quite a bit. And I've ensured that the "from" email matches the login email. i.e. I'm not trying to send from no-reply#mysite.com or similar.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { :host => 'www.mysite.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.office365.com',
:port => '587',
:authentication => :login,
:user_name => ENV['365_USERNAME'],
:password => ENV['365_PASSWORD'],
:domain => 'mysite.com',
:enable_starttls_auto => true
}
From discussions with support. I may need to add an SPF TXT record to allow emails to be sent from a remote server. The problem is, I have no idea what to add to the SPF record. My current spf record is:
v=spf1 include:spf.protection.outlook.com -all
Their response just says they have blacklisted your IP, so it’s not down to your message content.
If you are sending from Heroku, you may need to list them in your SPF as well. Also ensure that your host name resolves backwards as well as forwards - that should be possible in Heroku’s control panel.
Once you’ve done that, check your SPF record gives a pass to your message source using kitterman.com or mxtoolbox testing services.
O365’s spam filter and blocking policy is pretty bad anyway, however I have had success in asking their support to remove blocks, though you need to persevere because they reject all such requests by default. This is poor service, but it’s still far better than you will get from gmail.

Mail not sending from ewebguru domain Rails

I have a domain techo.com (bought from ewebguru) and I'm tryng to send mail from my rails app but mail is not sending I'm using following code configuration in production and development :
{
:user => 'abcd#techo.com',
:password => '*********',
:domain => 'techo.com',
:port => 25,
:authentication => :none
}
somebody suggest me to do these :
User: mail id
Password: mail id password
SMTP Server: tecorb.com
SMTP Port: 25
POP Port: 110
SSL Authentication:None
I'm not getting how to configure these into my development.
Please suggest me.
As I see your code, you are missing :address key in the configuration. Address for ewebguru is mahanadi.ewebguru.net (may be this address can be change but same for my domain purchased from ewebguru). Try configuration like this :
ActionMailer::Base.smtp_settings = {
:user_name => 'abcd#techo.com',
:password => '*******',
:server => 'techo.com',
:address=>"mahanadi.ewebguru.net"
}
Hope this will work.

Sendgrid set up on Rails 4

I have a rails 4 app. I set up ActionMailer and I can send order confirmation emails via localhost and gmail.
I installed Sendgrid on Heroku and followed the set up instructions. I get a Net::SMTPSyntaxError (501 Syntax error
my environment.rb (i have sendgrid user/pwd in application.yml)
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
}
in production.rb - the only actionamailer setting i have is this. I have this as a placeholder to put the real domain in later. I'm currently using herokuapp.com.
config.action_mailer.default_url_options = { host: 'localhost:3000' }
in my orders_controller within the order create method, I call the below.
AutoNotifier.orderconf_email(current_user, #order).deliver
auto_notifier.rb
class AutoNotifier < ActionMailer::Base
default from: "Test Email"
def orderconf_email(current_user, order)
#buyer = current_user
#order = order
mail(to: #buyer.email, subject: 'Thank you for your order.')
end
end
What am I missing? It works on localhost with gmail so I'm missing something in the sendgrid settings or in the default_url in production.rb file.
For posterity, here's a working setup for external SMTP in Rails on Heroku:
#config/environments/production.rb
config.action_mailer.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587, # ports 587 and 2525 are also supported with STARTTLS
:enable_starttls_auto => true, # detects and uses STARTTLS
:user_name => ENV["SENDGRID_USERNAME"],
:password => ENV["SENDGRID_PASSWORD"], # SMTP password is any valid API key, when user_name is "apikey".
:authentication => 'login',
:domain => 'yourdomain.com', # your domain to identify your server when connecting
}
Change default from: "Test Email" to valid email address, even example#example.com.
I would just like to point out, this is for sending emails via SMTP. While this method is totally ok, you should also consider sending via the API.
To do this, you need to specify an interceptor. Luckily, there's a Gem that helps with that. Here's a good article showing how to use it.
https://rubyplus.com/articles/561-Sending-Emails-using-SendGrid-API-in-Rails-4-1
It took us a long time to resolve the issue when we tried to deploy the SMTP relay on heroku. It worked perfectly fine on local but when pushed we received socket errors and time out issues. Eventually got it working.
Important note: Make sure not to use starttls_auto and SSL/or TLS this causes open SSL issue.

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.

Resources