
comprookie2000
By: a guest on
Jun 6th, 2009 | syntax:
Python | size: 1.46 KB | hits: 833 | expires: Never
#!/usr/bin/python
from time import sleep
import smtplib
import os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders
def send_mail(send_to, subject, text, files=[],
server="mail.yourserver.net"):
assert type(send_to)==list
assert type(files)==list
send_from = "Grateful User <user@grateful.net>"
msg = MIMEMultipart()
msg['From'] = send_from
msg['To'] = COMMASPACE.join(send_to)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach( MIMEText(text) )
for f in files:
part = MIMEBase('application', "octet-stream")
part.set_payload( open(f,"rb").read() )
Encoders.encode_base64(part)
part.add_header(
'Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
msg.attach(part)
smtp = smtplib.SMTP(server)
smtp.sendmail(send_from, send_to, msg.as_string())
smtp.close()
def message(address):
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"
send_mail(
[address],
"Thanks", body)
def send_message():
all_addresses = ['dev1@gentoo.com', 'dev2@gentoo.com']
for address in all_addresses:
message(address)
send_message()