-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/14/2011 12:48 PM, Ken wrote:
> How can I send html mail?

It doesn't really have anything to do with web.py, but here is an
example script I use to email me the woot.com deal of the day every
morning. Maybe this will help?

Tony
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNpz2LAAoJEAPVzrg8OofbFU0H/3BTG8sGpBY+ys8DsG9IwySJ
sWSD4rA+tZ+g8bFx1jbYpB2d6mFDj6q4hRjOB6zR3se/WQPpJ8bnAlQKqMYvSV9d
0ncgf3zien+HWx1KSjZ2wkDtDC8PXTYdWZx+pAUo9NGbworetpNnoC4Kt3uX95Uc
PJ3W/OCXpBiY5NaJnvXg1IUMbbU7oleLP9K/huryv+reGEhI3K3jkA/RXErrX+tB
fkTBaDFH6wthoaxF6zW57ouu0gP50PZ2V0oFHIHuP1Sm58Dsh/OYz1u5T3fe5IMx
aU7VHguX4AT7JnNN5SYKCB/wKD4jQzLqIpeEtRSDijof/+JfILQfGcv5ts8HDeI=
=hAFq
-----END PGP SIGNATURE-----

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to webpy@googlegroups.com.
To unsubscribe from this group, send email to 
webpy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

#!/usr/bin/python

from urllib import urlopen
from BeautifulSoup import BeautifulSoup
from smtplib import SMTP
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import parseaddr, formataddr

sender_name = 'Tony Awtrey'
sender_addr = 't...@awtrey.com'                                                                                                                      
recipient_list = { 'Ken':'qichangx...@gmail.com' }                                                                                                
subject = 'Woot Deal Of The Day'                                                                                                                     
header_charset = 'UTF-8'                                                                                                                             
body_charset = 'UTF-8'                                                                                                                               
                                                                                                                                                     
# Get the item and the amount from the website:
woot =  BeautifulSoup(urlopen("http://www.woot.com";).read())                                                                                         
item = woot.find(name='h2',attrs={'class':'fn'}).string
amount = woot.find(name='span',attrs={'class':'amount'}).string

# Fill in the item and amount in the body template
body = """\
Hello,

Woot is selling the following item today:

  %s
  $%s

You can click here to see it: http://www.woot.com/

Thank you,
The Management

P.S.
Don't forget the NewEgg daily Shell Shocker deal either!
http://www.newegg.com/special/shellshocker.aspx

""" % ( item, amount )

# Build the message headers
msg = MIMEText(body.encode(body_charset), 'plain', body_charset)
msg['From'] = formataddr((sender_name, sender_addr))

to_string = []
for name,addr in recipient_list.items():
  to_string.append(formataddr((name, addr)))

msg['To'] = ', '.join(to_string)
msg['Subject'] = Header(unicode(subject), header_charset)

# Send the email
smtp = SMTP('localhost') # put your email forwarding server here
smtp.sendmail( sender_addr, to_string, msg.as_string() )
smtp.quit()

# End

Reply via email to