Rails3: ECONNREFUSED Error in Mailer - ruby-on-rails-3

I have a controller in a Rails 3 app that, after creating a new object of type WorkRequest, sends an e-mail to the requester. Works for all of my users except one. When she tries it I get the following in the server log.
Started POST "/work_requests" for 172.16.42.150 at Mon Aug 08 14:42:53 -0400 2011
Processing by WorkRequestsController#create as HTML
Parameters: {"commit"=>" Save ", "authenticity_token"=>"GhhZ6S0mBaju2zs5Fc7M+u5SoLCke5CRSdVCvLzMK1Q=", "utf8"=>"✓", "work_request"=>{"work_due_date"=>"2011-12-01", "person_id"=>"525", "status"=>"Pending", "last_request_date"=>"", "requester_id"=>"5", "pier_module_id"=>"223"}}
Rendered person_mailer/work_request_init_email.html.erb (2.4ms)
Rendered person_mailer/work_request_init_email.text.erb (1.8ms)
Sent mail to hkitzmiller#acponline.org (409ms)
Completed in 548ms
Errno::ECONNREFUSED (Connection refused - connect(2)):
app/controllers/work_requests_controller.rb:57:in `create'
app/controllers/work_requests_controller.rb:54:in `create'
It appears to have sent the e-mail (she's left for the day so I can't ask if she received it) but the line it's failing on in the controller the line that invokes the mailer, so I'm not sure.
PersonMailer.work_request_init_email(#work_request).deliver
Can't seem to find any solid info on what ECONNREFUSED means. Is the mail server refusing the connect (in which case why does it appear the mail was sent?) or is the web server refusing to connect after the mail is sent.
What might cause either server to refuse a connection with this particular user?
Any help would be much appreciated. All the other users of the app seem to be working fine.

This generally is an error caused by a failed connection to the SMTP server. I'd say double check your settings in your environment files (production.rb most likely) and double check the email address. You might also check to see if there's a limit set by the SMTP server.

Related

Emails are added in queue but its not been send in otrs

I am using AWS SES to send emails from OTRS and emails are not working. Below is the error:
Mar 18 06:22:47 ip-10-210-28-141 OTRS-otrs.Console.pl-Maint::Email::MailQueue-09[30010]: [Error][Kernel::System::CommunicationLog::_LogError][Line:538]: CommunicationLog(ID:795,AccountType:-,AccountID:-,Direction:Outgoing,Transport:Email,ObjectLogType:Message,ObjectLogID:2233)::Kernel::System::MailQueue => Message could not be sent! Error message: Can't connect to email-smtp.us-east-1.amazonaws.com: !
I am able to telnet to email-smtp.us-east-1.amazonaws.com
I am able to send emails using SES from the same server via command line but OTRS is not sending email.
It's hard to debug OTRS. In your case OTRS was not possible to create an mail object. The cause can have several issue.
Maybe you are using the wrong SMTP backend module, there are 3 different options, SMTP/SMTPS and SMTPTLS (see also https://github.com/OTRS/otrs/tree/master/Kernel/System/Email)
To get more verbose feedback from the CPAN SMTP module, set $Self->{Debug} = 3; at this place https://github.com/OTRS/otrs/blob/master/Kernel/System/Email/SMTP.pm#L32 and check STDOUT what the problem is.

Problem in sending email with exim in cpanel to extern address

I noticed today that mails do not come through. Since several hours ago, all mails just get stuck in queue. I have tried to deliver them manually, by selecting one mail in WHM Mail Queue Manager and clicking on "Deliver Selected", but after few minutes I just get this error:
Code:
LOG: MAIN
cwd=/usr/local/cpanel/whostmgr/docroot 4 args: /usr/sbin/exim -v -M 1Tli6y-0002Xo-KW
delivering 1Tli6y-0002Xo-KW
Connecting to foobar.TLD [IP.ADDRESS]:25 ... failed: Connection timed out (timeout=5m)
LOG: MAIN
foobar.TLD [IP.ADDRESS] Connection timed out
LOG: MAIN
== info#foobar.TLD R=dkim_lookuphost T=dkim_remote_smtp defer (110): Connection timed out
I have searched on net, and I have found thread on this forum, similar error - http://forums.cpanel.net/f43/t-remote_smtp-defer-53-retry-time-not-reached-any-host-72383.html
and there is proposed solution, but I am not sure should it work in my case. I can not risk loosing emails in queue, my clients would hang me :)
I can see your server is unable to connect remote server to send your mail. Because you are getting "25 ... failed: Connection timed out" error in logs. I think your mail server IP is blacklisted in anti-spam databases and maybe due to that you are getting this issues.
run command
exim -bt info#foobar.tld
Copy ip address and add your CSF white list.
Or turn of Firewall and retest.

MCOErrorAuthentication performing background fetch

I'm fetching messages on background from IMAP server using performFetchWithCompletionHandler.
The first thing I do on method implementation is check for network reachability, discarding operation if its no available.
Then I start refresh process executing fetchMessagesOperationWithFolder on a IMAP session.
As result of this operation I usually receive no error, but sometimes I receive an MCOErrorParse (Unable to parse response from server), MCOErrorConnection (A stable connection to the server could not be established) or MCOErrorAuthentication (Unable to authenticate with the current session's credentials).
Can all this errors be produced due to connection failure?
I want to handle the MCOErrorAuthentication to notify user on the credentials error, but in this scenario the credentials are ok, so when I perform any operation when on foreground again with network reachability it will succeed.
Should I do an extra network connection check before proceed on those errors? Should I create a new IMAP session on every operation?
Thanks!
Edit
I'm adding ConnectionLog, it take me long to reproduce the error. Its very clear why I receive a MCOErrorAuthentation: I'm not loading password well.
2014-12-18 21:00:41.212 * OK Gimap ready for requests from 85.58.177.133 et58mb78762219web
2014-12-18 21:00:41.222 1 CAPABILITY
2014-12-18 21:00:41.302 * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN
1 OK Thats all she wrote! et58mb78762219web
2014-12-18 21:00:41.304 2 LOGIN “polferresamon#gmail.com" ""
2014-12-18 21:00:41.378 2 NO Empty username or password. et58mb78762219web
2014-12-18 21:00:41.380 Error fetching messages: Unable to authenticate with the current session's credentials.
So, to really solve MCOErrorAuthentication I have to check IMAP session init, and the process where I'm loading email and password when returning from background.
I guess parse and connection errors are due to connection issues.
Thanks for your help.

Heroku Intercepting Some Gmail Incoming Messages

I am serving my Rails 3 app on Heroku, my mail through Google, and the domain through Enom. This is for www.challengage.com
This works 95% of the time, however, once in a while, when someone tries to reply to an email I send them, it fails with the below error message because my email, josh#challengage.com, somehow got replaced with josh#herokuapp.challengage.com when they recieved it. I think it has something to do with Mail Delivery Subsystems, but I'm not sure. It also only seems to happen when emailing University professionals.
Error Message:
From: Mail Delivery Subsystem [mailto:MAILER-DAEMON#smtp2.syr.edu]
Sent: Monday, July 15, 2013 2:08 PM
To: David DiMaggio
Subject: Undeliverable: FW: Challengage - Work Team Simulation product for interviewing evaluations
Delivery has failed to these recipients or groups:
paul#challengage.herokuapp.com
The server has tried to deliver this message, without success, and has stopped trying. Please try sending this message again. If the problem continues, contact your helpdesk.
The following organization rejected your message: challengage.herokuapp.com.
Any ideas?
Thanks everyone.
This is almost certainly because you're using a CNAME for your email records.
Although most email servers will reflect the original domain when sending a message, others will replace it with the domain that's at the end of the CNAME.
This means that instead of sending to someone#challengage.com they send to someone#challengage.herokuapp.com instead.
The mail server sees the request to send to someone#challengage.herokuapp.com and decides that it doesn't look after challengage.herokuapp.com and so from it's perspective the message is rejected.
We used to see this issue with CloudMailin customers and started to recommend that they don't use CNAMES where email is involved and just make use of adding MX records direct to the Apex domain.
With Heroku this poses a problem though as you don't have a single IP that you can use to access their servers. We eventually ended up using Route 53 to host our domain, then adding an SSL endpoint (to get load balancer details) and then adding that load balancer to Route 53's Alias command so that it automatically always gave the correct results. Alternatively you can setup some sort of static IP based system on your apex domain to redirect.

MailMessage & MAIL/EXPN/VRFY/ETRN

I was told that my program was not issuing a MAIL/EXPN/VRFY/ETRN when sending an email by the web hosting company we are connecting to.
Anyone know what this means and how I do it?
I am sending an email with SmtpClient and I have no problems with other clients.
Here is what I was told:
Thanks for the additional info, here
is what I found...
Aug 4 11:16:48 smtp1 sendmail[2729]:
o74GGU5F002729:
xx-xx-xx-xx.static.xxx.mo.charter.com
[xx.xx.xx.xx] did not issue
MAIL/EXPN/VRFY/ETRN during connection
to TLSMTA
Notice the time and the IP address
which is your static from Charter. Now
here is a good connection.
Aug 4 11:18:22 smtp1 sendmail[2745]:
STARTTLS=server,
relay=xx.xx.xx.xx.static.xxx.mo.charter.com [xx.xx.xx.xx], version=TLSv1/SSLv3,
verify=NO, cipher=RC4-MD5,
bits=128/128 Aug 4 11:18:23 smtp1
sendmail[2745]: AUTH=server,
relay=xx.xx.xx.xx.static.stls.mo.charter.com
[xx.xx.xx.xx], authid=ronmid,
mech=LOGIN, bits=0
Since their email program did not
issue MAIL/EXPN/VRFY/ETRN during
connection, my server would not
continue the transaction.
Any suggestions?
Thanks!
You app didn't issue any of those 4 commands after connecting. This could be because the server didn't respond correctly and so your app was waiting for that response until it timed out. You can check this by trying to send an email with a simple telnet connection as described here. After you connect and send the EHLO or HELO command (depending on what the server wants) you should get a 250 response.
If you do get the 250 response with telnet but your app still doesn't work, then maybe it's something in your application that tries to send an incorrect command. Maybe you've setup your application to use SSL or credentials, and the SMTP server don't support that or something similar?