1

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

0

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.

Cambuchi
  • 102
  • 1
  • 9
  • Thank you for your response! STMP is built in to python, so it is not something I can install (from my understanding)? I checked if I had any broken dependencies and I do not. I have also tried every possible combination in the 'Action' table of my scheduled task and no luck. The code runs the export that I need and places it in the correct folder, but the email does not get sent that it is ready. – user14050490 Mar 17 '21 at 17:34