📄 smtp-example.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>11.10.2 SMTP Example </title>
<META NAME="description" CONTENT="11.10.2 SMTP Example ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="previous" href="SMTP-objects.html" tppabs="http://www.python.org/doc/current/lib/SMTP-objects.html">
<LINK REL="up" href="module-smtplib.html" tppabs="http://www.python.org/doc/current/lib/module-smtplib.html">
<LINK REL="next" href="module-telnetlib.html" tppabs="http://www.python.org/doc/current/lib/module-telnetlib.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="SMTP-objects.html" tppabs="http://www.python.org/doc/current/lib/SMTP-objects.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="module-smtplib.html" tppabs="http://www.python.org/doc/current/lib/module-smtplib.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-telnetlib.html" tppabs="http://www.python.org/doc/current/lib/module-telnetlib.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="SMTP-objects.html" tppabs="http://www.python.org/doc/current/lib/SMTP-objects.html">11.10.1 SMTP Objects</A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-smtplib.html" tppabs="http://www.python.org/doc/current/lib/module-smtplib.html">11.10 smtplib </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-telnetlib.html" tppabs="http://www.python.org/doc/current/lib/module-telnetlib.html">11.11 telnetlib </A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H2>
<BR>
11.10.2 SMTP Example
</H2>
<P>
This example prompts the user for addresses needed in the message
envelope (`To' and `From' addresses), and the message to be
delivered. Note that the headers to be included with the message must
be included in the message as entered; this example doesn't do any
processing of the <a class="rfc" name="rfcref-47180"
href="javascript:if(confirm('http://www.ietf.org/rfc/rfc0822.txt \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.ietf.org/rfc/rfc0822.txt'" tppabs="http://www.ietf.org/rfc/rfc0822.txt">RFC 822 <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a> headers. In particular, the `To' and
`From' addresses must be included in the message headers explicitly.
<P>
<dl><dd><pre class="verbatim">
import smtplib
import string
def prompt(prompt):
return string.strip(raw_input(prompt))
fromaddr = prompt("From: ")
toaddrs = string.split(prompt("To: "))
print "Enter message, end with ^D:"
# Add the From: and To: headers at the start!
msg = ("From: %s\r\nTo: %s\r\n\r\n"
% (fromaddr, string.join(toaddrs, ", ")))
while 1:
line = raw_input()
if not line:
break
msg = msg + line
print "Message length is " + `len(msg)`
server = smtplib.SMTP('localhost')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
</pre></dl>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="SMTP-objects.html" tppabs="http://www.python.org/doc/current/lib/SMTP-objects.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="module-smtplib.html" tppabs="http://www.python.org/doc/current/lib/module-smtplib.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-telnetlib.html" tppabs="http://www.python.org/doc/current/lib/module-telnetlib.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="SMTP-objects.html" tppabs="http://www.python.org/doc/current/lib/SMTP-objects.html">11.10.1 SMTP Objects</A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-smtplib.html" tppabs="http://www.python.org/doc/current/lib/module-smtplib.html">11.10 smtplib </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-telnetlib.html" tppabs="http://www.python.org/doc/current/lib/module-telnetlib.html">11.11 telnetlib </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -