send email to string of emails
Kun
neurogasm at gmail.com
Fri Mar 24 23:58:46 EST 2006
the code below outputs a string of emails (e.g. ['jon at jon.com',
'joe at joe.com']
i would like to somehow send an email to everyone on the string of
emails telling them 'thanks for emailing me'
anyone know how to do this? much thanks ahead of time.
from imaplib import *
import getpass, re
m = IMAP4("xxxxxxxxxxxxxx")
m.login('xxxxx', 'xxxxxx')
m.select('Inbox')
status, data = m.search(None,'(SUBJECT "BIKES")')
assert status=='OK', "Error. Message: %s"%data
data = data[0]
#you get your results in a list and search returns only one result
assert data,"No results"
#cool, we have results, but IMAP's search command only returns IDs so we
have to fetch
#msgs now
status,senders = m.fetch(data.replace(' ',','),'(BODY.PEEK[HEADER.FIELDS
(FROM)])')
assert status=='OK', "Error. Message: %s"%data
''.join([''.join(t) for t in senders])
senderlist =''.join([''.join(t) for t in senders])
emails = re.findall('(\w+@\w+\.\w+)', senderlist)
print emails
More information about the Python-list
mailing list