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.
Related
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?
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 believe that we are able to send email directly to destination MX server such as ('gmail-smtp-in.l.google.com', 25). However I can't connect to the mail server even with socket programming in Python 3.5.1.
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect(('gmail-smtp-in.l.google.com', 25))
Code above always gives me the following error at line 3.
TimeoutError: [WinError 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 found that people [1] are able to connect to the server stated above, please help me with this issue as I am still clueless about it after hours of research work carried out.
Note that I am running the code on a local computer.
[1]. How to send a mail directly to SMTP server without authentication?
I'm trying to run RabbitMQ Python tutorial but with sender on virtualbox host machine and receiver and queue on virtualbox guest machine. So I modified mentioned send.py code by only replacing localhost with 192.168.1.5. When I run it, i receive following error:
...
File "/home/damian/.virtualenvs/kivy_1.9/local/lib/python2.7/site-packages/pika/adapters/base_connection.py", line 153, in _check_state_on_disconnect
raise exceptions.ProbableAuthenticationError
pika.exceptions.ProbableAuthenticationError
rabbitmq-server seems to be running, because when I stop it send.py gives me:
...
File "/home/damian/.virtualenvs/kivy_1.9/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 301, in _adapter_connect
raise exceptions.AMQPConnectionError(error)
pika.exceptions.AMQPConnectionError: Connection to 192.168.1.5:5672 failed: [Errno 111] Connection refused
which makes perfect sense.
How to fix that ProbableAuthenticationError?
Host machine is Debian 7 with Python 2.7.3 and pika 0.9.14, guest is Ubuntu 15.04 with rabbitmq-server 3.4.3-2
This is because you are trying to authenticate using the username and password guest remotely. Starting with RabbitMQ 3.3 you need to create a new account to use remotely, and guest/guest can only be used locally.
This is taken from the change log here.
25603 prevent access using the default guest/guest credentials except via localhost since (1.0.0)
It's possible to modify the RabbitMQ configuration to allow remote access using the guest account, by removing guest from loopback_users, but it's recommended to create a new user to follow best practices.
[{rabbit, [{loopback_users, []}]}].
I am not a network/web/internet programmer so please excuse my noobness in this area. I have gotten a website using a free hosting service. They include one MySQL database. Here are the details for the database:
port = 3306
host = "fdb4.biz.nf"
database = "1284899_6067"
user = "1284899_6067"
password = "somepass9351"
I am using MySQLdb module (installed on my CLIENT machine - not server) to connect to this database:
db = MySQLdb.connect(host=host, user=user, passwd=password, db=database,port=port)
But I get the following error:
OperationalError: (2003, "Can't connect to MySQL server on 'fdb4.biz.nf' (10060)
What I have already tried
tried two different databases from different hosts
tried changing the port
tried searching SO for similar answers but all others connect to 'local host'
What I think:
could this be caused by my firewall? I am using my school's internet. I don't think this could be it because I am on CLIENT so if anything it is the SERVER'S firewall.
Two questions
Can MySQLdb be used to connect to a db on a SERVER when it is imported on a CLIENT?
If yes, what am I doing wrong?
Thank you so much for any help, its greatly appreciated! Been stuck the whole day on this.
For security reasons, mysql only listens for connections from localhost. Error code 10060 is basically that: you are not allowed to connect remotely.
Solution: find a my.ini (or my.cnf in linux) and try to find a line:
bind-address = 127.0.0.1
this line says: allow only local connections. So, you should comment-out this line, or set your IP address.
Yes, MySQLdb can connect to remote hosts.
And your usage of the connect method is correct.
You should first check if you can connect to the remote mysql server from your mysql client.
In terminal you can type mysql -h hostname -u username -p databasename
This should prompt you for the password. Enter the password. Can you connect?
If you can't connect, then you have an access problem, and its not a python - mysqldb problem
Either the server is not reachable because it is behind a firewall, in that case your client machine's ip needs to be whitelisted. Check your firewall settings
Or, the mysql server running on the remote machine is configured to accept only local connections. I think this is the default, but I'm not sure. You should ssh into the server remote host where the database server is running, locate the my.cnf file on the server and check the settings. Depending on your mysql version, the configuration would look slightly different.
Or, the user that you're trying to connect as is not associated with the ip that you're trying to connect from. Mysql users have two parts, like this: 'username'#'host'. To enable a user to connect from all ips the user needs to look like this 'user'#'%'.
I hope I've given you enough to try to debug this issue.