When no MTA is installed, How to send an email with a cronjob?
I usually do this:
import smtplib server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo() server.starttls() server.ehlo() server.login('user@gmail.com', password) server.sendmail(from, to, message_
Hi larry,
I think your method is the easiest way.
I currently have below cronjob that sends the output to /tmp/backup.out file. it is OK.
35 13 * * * root /root/scripts/backup.sh > /tmp/backup.out 2>&1
How can I then send this /tmp/backup.out to an email address.
Here's the one I created
[root@host ~]# ls -al /root/send_email.py -rwxr-xr-x. 1 root root 382 2013-07-23 15:18 /root/send_email.py
[root@host ~]# cat /root/send_email.py #!/usr/bin/python
import smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText
from_addr = 'root@host.example.com' to_addrs = ['myemail@gmail.com'] msg = open('/tmp/backup.out','r').read()
server = smtplib.SMTP('192.168.9.5', 25) server.sendmail("root@host.example.com", "myemail@gmail.com", msg) #server.sendmail(from_addr, to_addrs, msg)
Should I APPEND the PATH of the script (/root/send_email.py) to /root/scripts/backup.sh file. ?
I just ran this script (i.e - /root/send_email.py). It worked. I got the email. But no subject there. How can I add a subject called " CRON JOB OUTPUT " to the email receive .
Hope to hear from you.
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos