[CentOS] Fwd: When no MTA is installed, How to send an email with a cronjob?

Indunil Jayasooriya indunil75 at gmail.com
Tue Jul 23 10:07:06 UTC 2013


>
> > > 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 at 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 at host ~]# ls -al /root/send_email.py
-rwxr-xr-x. 1 root root 382 2013-07-23 15:18 /root/send_email.py


[root at host ~]# cat /root/send_email.py
#!/usr/bin/python

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText

from_addr = 'root at host.example.com'
to_addrs = ['myemail at gmail.com']
msg = open('/tmp/backup.out','r').read()

server = smtplib.SMTP('192.168.9.5', 25)
server.sendmail("root at host.example.com", "myemail at 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 at centos.org
> http://lists.centos.org/mailman/listinfo/centos
>



-- 
Thank you
Indunil Jayasooriya
http://www.theravadanet.net/
http://www.siyabas.lk/sinhala_how_to_install.html   -  Download Sinhala
Fonts



More information about the CentOS mailing list