Guest User

getGmailInfo

a guest
Feb 28th, 2010
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. #
  3. # This is the application core, it only contains methods used by
  4. # both the graphical and text interfaces.
  5. #
  6. # TODO: See above.
  7. #
  8.  
  9. import smtplib
  10. from email.MIMEMultipart import MIMEMultipart
  11. from email.MIMEText import MIMEText
  12. import carrier
  13.  
  14. class Core:    
  15.     def __init__(self, username, password):
  16.         # code could be added here to auto load these from a file
  17.         self.gmail_user = username
  18.         self.gmail_pwd = password
  19.  
  20.     # Send one text to one number
  21.     # TODO: send to multiple addresses
  22.  
  23.     def mail(self, to, text):
  24.        msg = MIMEMultipart()
  25.  
  26.        msg['From'] = self.gmail_user
  27.        msg['To'] = to
  28.  
  29.        msg.attach(MIMEText(text))
  30.  
  31.  
  32.        mailServer = smtplib.SMTP("smtp.gmail.com", 587)
  33.        mailServer.ehlo()
  34.        mailServer.starttls()
  35.        mailServer.ehlo()
  36.        mailServer.login(self.gmail_user, self.gmail_pwd)
  37.        mailServer.sendmail(self.gmail_user, to, msg.as_string())
  38.        # Should be mailServer.quit(), but that crashes...
  39.        mailServer.close()
  40.  
  41.     def texto(sendtoaddress, messagetext):
  42.         numbersendlist = []
  43.         for number in sendtoaddress:
  44.             numbersendlist.append(carrier.carriercheck(number))
  45.  
  46.         for number in numbersendlist:
  47.             core.mail(number, messagetext)
  48.  
  49.     texto(['1112223333'], 'hi. this better work.')
Advertisement
Add Comment
Please, Sign In to add comment