-
Assuming the Web2Py application has the mail object defined already...Create python script sendmail.py :
import datetime EmailSubject = 'Backup from PythonAnywhere sent at '+ str(datetime.datetime.now()) mail.send(to='myemail@gmail.com', subject=EmailSubject, message='Find the attached', attachments = [mail.Attachment('/path/to/file1.file'), mail.Attachment('/path/to/file2.file')])
-
Upload python script to web2py/applications/
- Create a bash script to run the python script as part of the app named app - as per the web2py book:
python /home/app/web2py/web2py.py -S app -M -R applications/sendmail.py
- Give permissions to the bash file: chmod 700 /path/to/file.sh
- Add the script to the scheduler at xx mins past or other frequency
That's it ! An email with attachment will be sent automatically.