AWS SES simple email service, time out error with Zend email - ssl

I was using Amazon AWS SES simple email service to send emails for my application. I using the following codes of Zend framework2 to send emails. It worked fine before, but I got the following error in my AWS EB EC2 instance now. However in my localhost, I can still use the same code and the same AWS SES account to send emails and it is still working fine now in my localhost.
$sc_Zend_mail_smtpOptions = new \Zend\Mail\Transport\SmtpOptions();
$sc_Zend_mail_smtpOptions->setHost($sc_server_email_host)
->setConnectionClass('login')
->setName($sc_server_email_host)
->setConnectionConfig(array(
'username' => $sc_server_email_account,
'password' => $sc_server_email_password,
'ssl' => 'tls',
'port' => 587
));
$sc_Zend_mail_transport = new \Zend\Mail\Transport\Smtp($sc_Zend_mail_smtpOptions);
Is the problem from AWS EB EC2 ssl setting ? What is wrong with the codes? It was working fine in AWS EC2 before.
The error message is:
Fatal error: Uncaught exception 'Zend\Mail\Protocol\Exception\RuntimeException'
with message 'Connection timed out' in /var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/AbstractProtocol.php:209 S
tack trace: #0 /var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(148): Zend\Mail\Protocol\AbstractProtocol->_connect('tcp://email-smt...')
#1/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(375): Zend\Mail\Protocol\Smtp->connect()
#2/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(361): Zend\Mail\Transport\Smtp->connect()
#3/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(372): Zend\Mail\Transport\Smtp->lazyLoadConnection()
#4/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(229): in /var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/AbstractProtocol.php on line 209

It seems that server instance in AWS EC2 does not allow the old port set up any more. Moving the port setup outside setConnectionConfig array does make it work in AWS EB EC2 again as well as in localhost.
$sc_Zend_mail_smtpOptions->setHost($sc_server_email_host)
->setConnectionClass('login')
->setName($sc_server_email_host)
->setPort(587)
->setConnectionConfig(array(
'username' => $sc_server_email_account,
'password' => $sc_server_email_password,
'ssl' => 'tls'
));

Related

Logstash can't connect to my RabbitMQ Broker

I'm trying to connect a Logstash instance, running in a docker container, to an Amazon MQ Broker.
My ultimate goal is to insert the MQ message bodies into ElasticSearch
Based on the logs, I think Logstash is able to reach the MQ Queue, but the error message doesn't give any other info:
[2021-05-21T23:30:53,226][ERROR][logstash.inputs.rabbitmq ][instance_journal_pipeline][rmq_instance_source]
RabbitMQ connection error, will retry. {
:error_message=>"An unknown error occurred. RabbitMQ gave no hints as to the cause. Maybe this is a configuration error (invalid vhost, for example). I recommend checking the RabbitMQ server logs for clues about this failure.",
:exception=>"Java::JavaIo::IOException"
}
My input config is as follows:
input {
rabbitmq {
id => "rmq_instance_source"
ack => true
durable => true
passive => true
exchange => "events"
exchange_type => "topic"
host => "${AWS_MQ_URL}"
user => "${AWS_MQ_USER}"
port => "${AWS_MQ_PORT}"
password => "${AWS_MQ_PASSWORD}"
queue => "outbound_task_queue_name"
key => "outbound_task_key"
arguments => {
# arguments reproduced from the RMQ Queue's admin page
}
}
}
Turns out that this was an SSL configuration issue. The RMQ Logstash plugin requires you to specify that the server is using SSL, and version. The error message does not tell you that this is the case. Verify your SSL version with your MQ Broker.
I added the following params to my config (to match the Amazon MQ configuration) and that solved it:
ssl => true
ssl_version => "TLSv1.2"

Roundcube SSL connection IMAP Error: Login failed

This is probably a reoccurring problem, where you are unable to Login to Roundcube (Connection to storage server failed), due to an IMAP (ssl) connection error.
Many Posts reports this as an IMAP issue, and tells you that this is due to the config/config.inc.php Imap configuration, but are failing to give any proper debugging of the IMAP.
So, this is another post, of the same problem : Unresolved.
Roundcube reports this error:
IMAP Error: Login failed for user#myserver.com against host.myserver.com from IP_ADDRESS. Could not
connect to ssl://host.myserver.com:993: Unknown reason in
../lib/Roundcube/rcube_imap.php on line 200 (POST /webmail/?_task=login&_action=login)
I tried this to check if ssl connection to imap was possible:
openssl s_client -connect host.myserver.com:993
And I am able to connect to the IMAP with ssl, but connection ends with :
BYE Too many invalid IMAP commands.
So ... it seem that the ssl certificate is valid, and I am able to connect on port 993.
Roundcube still reports an Unknown reason for not connecting properly.
The certificate was generated by the ./mkcert.sh bash script, where you can enter the proper hostname of your server, to be included in the certificate.
After a lot of debugging, and no proper debugging methodology I found the easy solution, by bypassing ssl verification.
A stupid solution:
$config['imap_conn_options'] = array(
'ssl' => array(
'verify_peer' => false,
'verfify_peer_name' => false,
),
);
$config['smtp_conn_options'] = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
);
Do anyone have some suggestions for the next thing to try
Thanks!

Rails App on AWS Elasticbeanstalk mail send fails with ESMTP No Relay Access Allowed From IP

I have a rails app that I have deployed to AWS Elastic Beanstalk. The app uses devise to handle user authentication, and its set to be able to invite users.
My issue is that when I try to invite a user, I get the following error:
Net::SMTPFatalError (554 secureserver.net ESMTP No Relay Access Allowed From <my_eb_assigned_ip>
(I am hosting the domain on GoDaddy).
In development, the mailer functionality works fine; my smtp settings are set to (common to all environments):
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtpout.secureserver.net",
:port => 80,
:domain => "www.my_domain.com",
:authentication => :plain,
:user_name => "do-not-reply#my_domain.com",
:password => my_pass,
}
And in my production.rb config file:
config.action_mailer.default_url_options = { :host => 'aws_sb.elasticbeanstalk.com' }
Is there another setting I have to enable in Elasticbeanstalk to allow relay access? Or am I missing a production specific setting from my rails configuration?
I figured out it was the port value that I was setting....when I switched the port to 25, it works in production. However, for development, port 25 wasn't working; it would only work in dev when the port was 80.
So I ended up moving the entire smtp mailer settings into the environment specific settings (from the config/environment.rb file), and setting the production port to 25, and the development port to 80, and that appeared to make both environments work.
Edit: After another push, I was seeing the same issue, and none of the ports I tried were resolving the issue. So I ended up switching all my mail functionality to be sent through Amazon SES, and that appears to be functioning great so far.

Gmail smtp Hostname does not match the server certificate

I'm having an error with gmail gem while trying to send a mail, this is working fine on local, and was working fine on heroku, but now im moving this app to a VPS server. This is the error:
e = g.compose do
to 'test#gmail.com'
subject 'testasea'
body 'test'
end
=> #<Mail::Message:25450040, Multipart: false, Headers: <From: .......>
e.deliver!
=> OpenSSL::SSL::SSLError: hostname does not match the server certificate
I've added this into an initializer file, without any luck:
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:openssl_verify_mode => 'none' # I've tested with 0 and false,
}
I tried to monkey path the class
OpenSSL::SSL::SSLSocket.class_eval do
def post_connection_check(hostname)
return true
end
end
with no luck, when I do that i receive a 535 Incorrect authentication data, however I know data is ok because i can do
g.inbox.count :read
And it returns me the right number.
I would like to know:
the incorrect certificate is the one my server (smtp client) is sending? or the one that is received by gmail smtp server?
why it works in local?
Why if i monkey path the class I received an authentication error?
Is there any workaround? i dont care if is not safe, is just a tenting application,.
This is only a guess, but if you are in a WHM VPS there is a function that restricts outgoing SMTP connections, you can find it in Tweak Settings.
Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak)
It redirects all SMTP connections, If this is enabled you will receive your server self-signed ssl certificate, and if you bypass it using the monkey patch or setting configuration to dont check ssl certificate you will probably found an authentication error as you are in fact connecting to the LOCAL SMTP server.
Just disable it and test again.

mandrill send e-mail from localhost

I'm using Mandrill to build a feedback form for users on the website (they fill the form and send me an e-mail).
I want to test the e-mail functionality in development. I use unicorn as a server and my local address is 0.0.0:8080
However I get a 500 server error, Net::SMTPServerBusy : Relay Access Denied
I followed the Heroku instructions step by step.
Here is m application.rb configuration:
config.action_mailer.smtp_settings = {
:address => 'smtp.mandrillapp.com',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['MANDRILL_USERNAME'],
:password => ENV['MANDRILL_APIKEY']
}
ActionMailer::Base.delivery_method = :smtp
I followed the instructions on mandrill/heroku web page to set up.
I have a .env file set up with a MANDRILL_USERNAME and my MANDRILL_APIKEY
Here is my ActionMailer file:
class FeedbackMailer < ActionMailer::Base
default :from => ""
default :to => "xxx#stanford.edu"
default :subject => "feedback about xxx"
def send_feedback(message)
#debugger
#message = message
mail(:from => message[:sender_email])
end
end
Any help would be appreciated.
I can confirm e-mails get sent in production.
If all of your settings are working in production but not locally, there are a couple of possibilities:
How are you loading the variables from .env to ENV? It's possible the environment variables aren't getting loaded as expected locally. If you hard code the credentials locally, does it work?
You could be running in to an issue with the port or outbound SMTP traffic being blocked. Consider trying port 2525, as it may be less likely to be blocked by local ISPs. Port 465 with SSL enabled may also work even if your ISP is blocking other SMTP traffic