I am having trouble getting task scheduler to send an email via python. The particular python code I am using creates a monthly export, grabbing data from a SQL database, and then sends an email notifying the team where the export is located. For the email, I am using smtplib.
Here is the issue. I can run the export from pycharm, and the export and the send email works fine. I can run the export from task scheduler and JUST the export runs. In other words, only when I run the .bat file of the code from task scheduler, the email doesn't send. Does anyone happen to know the solution? I've tried so many things from searches and nothing works. :(
The answer really depends on how you've packaged your code and how you are choosing to execute it.
To me it seems like you are executing it as a script that your task scheduler is pointed to, if this script calls your system interpreter, my first suggestion would be to make sure you have all of the dependencies installed for the version of python that your script is calling. So if you are calling python 3.9.1, then make sure smtplib is installed on your system's python for 3.9.1.
For why it's working in pycharm, code in pycharm is run in an isolated environment, so packages that you have installed for your project will only work on that specific project. Not outside of it or on other systems.
Running python export that includes a send email trigger through task scheduler not working?