Re: using the email module
- From: "Tim Williams" <tim@xxxxxxx>
- Date: Thu, 28 Sep 2006 19:33:57 +0100
On 28/09/06, Erik Johnson <ej <at@xxxxxxxxxxxxxx>wellkeeper dot
<"com>"@bag.python.org> wrote:
#!/usr/bin/env python
import smtplib
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
# GLOBAL DATA
#=============
MAIL_SERVER = 'your_server.com'
MAIL_SUBJECT = "Python.SMTP email test"
MAIL_TO = 'your_addr@xxxxxxxxxxx'
MAIL_FROM = "Python.SMTP email test"
# Create a text/plain message
Body = """\
This is intended to be the body of my email. The HTML below should not
be seen directly in the body but should be a separate attachment.
"""
msg = MIMEMultipart()
msg['Subject'] = MAIL_SUBJECT
msg['From'] = MAIL_FROM
msg['To'] = MAIL_TO
msg.preamble = Body
html = """\
<html>
<head>
<title>Sample HTML File</title>
</head>
<body>
<h1>Can you see this?</h1>
<p>This is a short paragraph.</p>
</body>
</html>
"""
html_part = MIMEText(html, _subtype='html')
html_part.add_header('Content-Disposition', 'attachment',
filename='my_text.html')
msg.attach(html_part)
# msg.attach(MIMEText(html, 'html')).
# print msg.as_string()
# Send the message via our own SMTP server, but don't include the
# envelope header.
smtp = smtplib.SMTP(MAIL_SERVER)
smtp.sendmail(MAIL_FROM, [MAIL_TO], msg.as_string())
smtp.close()
# end of python script
- Prev by Date: Re: how do you know if open failed?
- Next by Date: Re: ctypes.c_void_p(-1) might not be C return (void *) -1
- Previous by thread: Re: using the email module
- Next by thread: help tranlating perl expressions
- Index(es):