Send mail with attachment on schedule using Web2Py

  1. Assuming the Web2Py application has the mail object defined already...Create python script :

    import datetime EmailSubject = 'Backup from PythonAnywhere sent at '+ str( mail.send(to='', subject=EmailSubject, message='Find the attached', attachments = [mail.Attachment('/path/to/file1.file'), mail.Attachment('/path/to/file2.file')])

  2. Upload python script to web2py/applications/

  3. 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/ -S app -M -R applications/

  1. Give permissions to the bash file: chmod 700 /path/to/
  2. Add the script to the scheduler at xx mins past or other frequency

That's it ! An email with attachment will be sent automatically.