gmail script

programming/python 2013. 6. 20. 17:08 |

#!/usr/bin/python

import sys

import smtplib

from email.MIMEText import MIMEText


sender = 'sdfsdfsdf@gmail.com'

recipients = 'sdfsdfsdf@gmail.com'

text = sys.argv[1]

msg = MIMEText(text)

msg['Subject'] =  '[Alert'

msg['From'] = sender

msg['To'] = recipients


smtpserver = 'smtp.gmail.com'

smtpuser = 'asdfasft'         # set SMTP username here

smtppass = 'asfdasdf'   # set SMTP password here


session = smtplib.SMTP("smtp.gmail.com", 587)

session.ehlo()

session.starttls()

session.ehlo()


session.login(smtpuser, smtppass)


smtpresult = session.sendmail(sender, [recipients], msg.as_string())


if smtpresult:

  errstr = ""

  for recip in smtpresult.keys():

      errstr = """Could not delivery mail to: %s


Server said: %s

%s


%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)

  raise smtplib.SMTPException, errstr


session.close()



Posted by applicationlayer
: