Don't like ads? PRO users don't see any ads ;-)
Guest

comprookie2000

By: a guest on Jun 6th, 2009  |  syntax: Python  |  size: 1.46 KB  |  hits: 833  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/python
  2. from time import sleep
  3. import smtplib
  4. import os
  5. from email.MIMEMultipart import MIMEMultipart
  6. from email.MIMEBase import MIMEBase
  7. from email.MIMEText import MIMEText
  8. from email.Utils import COMMASPACE, formatdate
  9. from email import Encoders
  10.  
  11. def send_mail(send_to, subject, text, files=[],
  12.               server="mail.yourserver.net"):
  13.     assert type(send_to)==list
  14.     assert type(files)==list
  15.     send_from = "Grateful User <user@grateful.net>"
  16.  
  17.     msg = MIMEMultipart()
  18.     msg['From'] = send_from
  19.     msg['To'] = COMMASPACE.join(send_to)
  20.     msg['Date'] = formatdate(localtime=True)
  21.     msg['Subject'] = subject
  22.  
  23.     msg.attach( MIMEText(text) )
  24.  
  25.     for f in files:
  26.         part = MIMEBase('application', "octet-stream")
  27.         part.set_payload( open(f,"rb").read() )
  28.         Encoders.encode_base64(part)
  29.         part.add_header(
  30.             'Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
  31.         msg.attach(part)
  32.  
  33.     smtp = smtplib.SMTP(server)
  34.     smtp.sendmail(send_from, send_to, msg.as_string())
  35.     smtp.close()
  36.  
  37. def message(address):
  38.     body = "Just a short note to say thank you for all the time and work you put into Gentoo.\n user aka (gentoo_guru)\n\n http://linux.com"
  39.     send_mail(
  40.         [address],
  41.         "Thanks", body)
  42.  
  43. def send_message():
  44.     all_addresses = ['dev1@gentoo.com', 'dev2@gentoo.com']
  45.     for address in all_addresses:
  46.         message(address)
  47.  
  48. send_message()