We are using Elasticemail for our SMTP server and running in issues where our server would fail to connect to the SMTP server for various reasons. Currently, we only find out about the issue when a user complains.
We want to monitor the connection to the server on a regular interval and notify Admin if there is a connection failure.
Is there any way to test the connection to the server without sending an actual email using Python3?
Related
Following something similar as explained in below article for sending emails via SMTP server in Airflow:
https://towardsdatascience.com/automating-emails-in-apache-airflow-a-how-to-guide-1d2330a29d1e
I didn't use default airflow.cfg to configure for smtp host as in our production env, we don't have control over it.
But in prod, seems Airflow is not able to connect to the SMTP host, while I could run the same code in local and get the emails.
Error as below:
Error description
We also checked via a standalone python script on prod server, that we're able to reach to SMTP host, so it's not really issue with the host but Airflow.
Any suggestions on this?
Well, we found it’s the issue connecting from production boxes to the remote SMTP server, probably due to a firewall between client and server.
We confirmed it via running a python script in those prod boxes and it’s failing at below line while connecting:
server = smtplib.SMTP(smtp_server)
server.sendmail(sender_email, receiver_email, message.as_string())
Error:
ConnectionRefusedError: [Errno 111] Connection refused
Apologies for confusion before.
Earlier we tried via sendmail unix command and it worked and so the confusion:
sendmail email_address -s smtp_server
Subject: Test mail from prod_env
Hello, email received
So it’s not issue with Airflow, but just connecting from prod servers to smtp server.
Thanks.
I am using paramiko to create a SFTP server. I have succeeded in uploading and downloading files to and from server on client request.But, I need to send a file from server to client whenever I need without client request. So, instead of breaking my head on making server send a file to client I want to make both machines act as both server and client in different ports so that when I need to send a file from machine A to B I can just Upload it to the SFTP server running on that port. Is this hypothesis possible?
You already know that you cannot send a file from an server to a client:
Can I send a file from SFTP Server to the Client without any request from it?
(The question on Server Fault has been deleted)
To answer your port question:
You do not care about client's port. It is automatically assigned to any available port, without you ever needing to know its value. In general, that's true for any TCP/IP connection, not only SFTP.
So you can just run SFTP server on both machines on the standard port 22. And use your client code on the other machine to connect to it.
My code is as follows:
I always get this error when I try to send a email. Could you help me.
error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I recommend reading the example in the manual located at https://docs.python.org/3/library/smtplib.html
You would need to make sure your firewall operating system and LAN router allows outgoing traffic on port 25.
Also, set verbose debug level as per manual server.set_debuglevel(1)
Try sending out test emails via localhost using terminal commands, to make sure the os can definitely send out emails, and that it isn't a python code issue.
I'm trying to send emails using python smtp library but get the following an error message when trying to send to external email addresses (internal email works):
smtplib.SMTPRecipientsRefused: {'test#gmail.com': (550, ' Relaying denied')}
This is because we have rules setup on our exchange that prevent relaying from client machines.
What I don't understand is how come I can send emails over SMTP with an SSIS package without getting the relay error.
Is there a setting I need to enable in my python to bypass this or is SSIS sending the email to SQL Server to send on its behalf.
I believe you are getting this due to authentication. SSIS is probably passing your windows credentials through but when you are trying to send with python your credentials are being denied.
Not 100% sure that is your issue. But a thought.
A Python web server started with
python -m SimpleHTTPServer
will print on the console requests it has accepted. Can I get it to print requests that returned a connection refused to the client?
I am trying to debug why it refuses some requests from an Android client.
No. If the client gets a Connection refused, this means that the connection request did not reach the server application. Therefore, the server application cannot possibly register these errors.
Check firewalls, routing, connectivity, and correctness of server address and port.