def sendMail():
    sendmail_location = '/usr/sbin/sendmail'
p = os.popen('%s -t' % sendmail_location, 'w')
p.write('From: %s\n' % 'from@somewhere.com')
p.write('To: %s\n' % 'to@somewhereelse.com')
p.write('Subject: thesubject\n')
p.write('\n')
p.write('body of the mail')
status = p.close()
if status != 0:
    pass
Sending mail via sendmail from python