From: Alexey Morsov <samurai@ricom.ru>
To: community@lists.altlinux.org
Subject: Re: [Comm] Рассылка почты
Date: Fri, 4 Jul 2008 10:39:36 +0400
Message-ID: <20080704063936.GA1601@ricom.ru> (raw)
In-Reply-To: <486CE45C.2070807@pochta.ru>
[-- Attachment #1.1: Type: text/plain, Size: 792 bytes --]
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@
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: massmail_example --]
[-- Type: text/plain; charset=utf-8; name=massmail_example, Size: 2590 bytes --]
#!/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()
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 489 bytes --]
next prev parent reply other threads:[~2008-07-04 6:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-03 9:41 Ilya Raskin
2008-07-03 11:33 ` Sergey
2008-07-03 11:51 ` Ilya Raskin
2008-07-03 14:07 ` Alexey Morsov
2008-07-03 14:38 ` Ilya Raskin
2008-07-03 15:06 ` Timur Batyrshin
2008-07-03 15:14 ` Ilya Raskin
2008-07-03 15:17 ` Ilya Raskin
2008-07-05 11:10 ` Vitaly Ostanin
2008-07-05 15:22 ` Ilja Raskin
2008-07-05 22:18 ` Michael Shigorin
2008-07-04 6:39 ` Alexey Morsov [this message]
2008-07-04 12:05 ` Ilya Raskin
2008-07-05 15:25 ` Sergey
2008-07-05 20:12 ` Ilja Raskin
2008-07-05 22:13 ` Michael Shigorin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080704063936.GA1601@ricom.ru \
--to=samurai@ricom.ru \
--cc=community@lists.altlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Community general discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
public-inbox-index community
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.community
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git