Question: I have python code that looks like below. It works fine when executed manually. But when executed via a cronjob, the email is not being sent. Here is the code:

```
msg = MIMEMultipart()

msg['From'] = sender
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(message))

mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(login, password)
print mailServer.sendmail(login, to, msg.as_string())

```

Answer: 
There are a number of reasons why this could fail:

1. The file you want to write (`courses.dmp`) does *already* exist. Oracle
won't override the file. (Yes, the error message is pretty lame)
2. The OS-directory `/mydata/data` does *not* exist.
3. `/mydata/data` *does* exist, but Oracle does not have the necessary 
rights to access the directory
4. None of the above, but the Oracle user that runs the script was not
granted `read, write` on `dpump_dir`

If these points don't help, you might first open (`add_file`) the \*.log file, *then* the \*.dmp file. Hopefully, Oracle will write something meaningful into the \*.log file.
It appears your error is occurring on the first ADDFILE call.

Try making your directory references upper case: directory => 'DPUMP\_DIR'