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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



>
> > > 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@xxxxxxxxx', 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@xxxxxxxxxxxxxxxx'
to_addrs = ['myemail@xxxxxxxxx']
msg = open('/tmp/backup.out','r').read()

server = smtplib.SMTP('192.168.9.5', 25)
server.sendmail("root@xxxxxxxxxxxxxxxx", "myemail@xxxxxxxxx", 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@xxxxxxxxxx
> 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
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos




[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux