0

After a successful execution of a bash-script I need to send a mail to other domain, without a mail configure in the sender machine.

If it possible to execute a python script inside a bash-script for sending mail with bash variables?

Or any other way to share the same variables from a shell-script to a python script?

I found a python script for sending mail,

#!/usr/bin/python    
from smtplib import SMTP
import datetime
debuglevel = 0

smtp = SMTP()
smtp.set_debuglevel(debuglevel)
smtp.connect('192.168.75.1', 25)
smtp.login('my_mail', 'mail_passwd')

from_addr = "My Name <my_mail@192.168.75.1>"
to_addr = "<my_mail@192.168.75.1"
subj = "Process completed"
date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" )
#print (date)
message_text = "Hai..\n\nThe process completed."

msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % ( from_addr, to_addr, subj, date, message_text )

smtp.sendmail(from_addr, to_addr, msg)
smtp.quit()

But I need to execute this on the same script, because the bash-script parameters must be the body of the mail.

  • you can execute the bash from python using subprocess and use the output in your python script – Padraic Cunningham Feb 13 '15 at 18:19
  • What do you mean "without a mail configure in the sender machine"? Do you mean there is no SMTP agent running on the sender machine? If there is an SMTP agent, you can use one of the many Unix mail programs such as `mail`, `mailx`, `nail`, etc. – dg99 Feb 13 '15 at 18:36
  • How to use subprocess in a bash-script? please give an example – Amal P Ramesh Feb 13 '15 at 18:41
  • see http://stackoverflow.com/questions/8260858/how-to-send-email-from-terminal – Farvardin Feb 13 '15 at 18:41

0 Answers0