[Comm]

Alexey Morsov =?iso-8859-1?q?samurai_=CE=C1_ricom=2Eru?=
4 10:39:36 MSD 2008


On Thu, Jul 03, 2008 at 06:38:20PM +0400, Ilya Raskin wrote:
> А можно поглядеть на это чудо?
> А то все что вроде по функциональности 
> подходит - для выньды. а sympa собираться 
> отказалась. :(
Приатачил.
Адреса достаются из MySQl, но вам никто не машет или доставать их из
текстового файла или таки загнать их экселя в БД :)

-- 
WBR,
Alexey Morsov
программист ЗАО "ИК "Риком-Траст"
Jabber: samurai  www.fondmarket.ru
ALT Linux Team Member

Переход пактов из рук в руки вызывает дрейф багов.
		-- at in devel@
----------- следующая часть -----------
#!/usr/bin/python
#-*- mode: python; coding: koi8-r -*-

import sys, os
from StringIO import StringIO
import os
import MySQLdb
from string import split, lstrip, rstrip
from email import *
import smtplib



def emailing(list_id, text, filename=None, attach=None, filetype=None):
	msg = MIMEMultipart.MIMEMultipart()

	db = MySQLdb.connect(host='', db='', user='', passwd='')

	msg['Subject'] = Header.Header(" ","koi8-r").encode()
	    
	msg['From'] = Utils.formataddr((Header.Header("  ","koi8-r").encode(),
		'postmaster  yourdomain.com'))

	message = StringIO()

	message.write(text)
	txt = MIMEText.MIMEText(message.getvalue(),'plain','koi8-r')
	message.close()
	msg.attach(txt)

	if filename:
		doc = MIMEBase.MIMEBase('application',filetype)
		doc.set_payload(attach)
		Encoders.encode_base64(doc)
		doc.add_header('Content-Disposition', 'attachment', filename=filename)
		msg.attach(doc)

	# cycle through the emails of subscribers
	cur.execute("select email from youremaildtable")
	for line in cur.fetchall():
		try:
			msg.replace_header('To',Utils.formataddr(('',line[0])))
		except KeyError:
			msg['To'] = Utils.formataddr(('',line[0]))
		s = smtplib.SMTP()
		s.connect()
		try:
			s.sendmail('postmaster  yourdomain.com', line[0], msg.as_string())
		except smtplib.SMTPRecipientsRefused, msg:
			s.sendmail('postmaster  yourdomain.com', 'postmaster  yourdomain.com', 
					"To: <postmaster  yourdomain.com>\nSubject: Maillist send error\n\n%s"%(msg))
		s.close()

	cur.close()
	db.close()




def main():
	buf = StringIO()

	map(buf.write,sys.stdin)
	msg = message_from_string(buf.getvalue())
	buf.close()

	print rstrip(lstrip(split(msg.get('Return-Path'))[-1],'<'),'>')
	if rstrip(lstrip(split(msg.get('Return-Path'))[-1],'<'),'>') == 'postmaster  yourdomain.com':
		subj = Header.decode_header(msg.get('Subject'))[0][0]
		for part in msg.walk():
			if part.get_content_type() == 'text/plain':
				text = part.get_payload(decode=1)
				filetype = 'text'
			if part.get_content_type() == 'application/msword':
				filename = Header.decode_header(part.get_filename())[0][0]
				attach = part.get_payload(decode=1)
				filetype = 'word'
			if part.get_content_type() == 'application/pdf':
				filename = Header.decode_header(part.get_filename())[0][0]
				attach = part.get_payload(decode=1)
				filetype = 'pdf'
			else:
				filename = None
				attach = None
				filetype = None
		emailing(subj,text,filename,attach,filetype)


if __name__ == '__main__':
	main()

----------- следующая часть -----------
Было удалено вложение не в текстовом формате...
Имя     : =?iso-8859-1?q?=CF=D4=D3=D5=D4=D3=D4=D7=D5=C5=D4?=
Тип     : application/pgp-signature
Размер  : 489 байтов
Описание: Digital signature
Url     : <http://lists.altlinux.org/pipermail/community/attachments/20080704/e9516d70/attachment-0002.bin>


community