{"id":1637,"date":"2020-06-21T21:03:55","date_gmt":"2020-06-21T13:03:55","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1637"},"modified":"2020-06-21T21:03:55","modified_gmt":"2020-06-21T13:03:55","slug":"%e4%bd%bf%e7%94%a8-python-%e5%8f%91%e9%80%81%e7%94%b5%e5%ad%90%e9%82%ae%e4%bb%b6","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1637","title":{"rendered":"\u4f7f\u7528 Python \u53d1\u9001\u7535\u5b50\u90ae\u4ef6"},"content":{"rendered":"<div>\n<div>\n<div>\n<div>\u4f7f\u7528 Python \u7684 smtplib \u6a21\u5757\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u53d1\u9001\u90ae\u4ef6\u3002<\/div>\n<\/div>\n<\/div>\n<\/div>\n<article>\n<h2>1 \u7535\u5b50\u90ae\u4ef6\u670d\u52a1\u5668<\/h2>\n<p>\u5982\u679c\u662f\u7f51\u6613 163 \u90ae\u7bb1\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u767b\u9646\u00a0<a href=\\\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fmail.163.com%2F\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">https:\/\/mail.163.com\/<\/a>\u00a0\u90ae\u7bb1\u540e\uff0c\u4f9d\u6b21\u70b9\u51fb \u8bbe\u7f6e \u2192 POP3\/SMTP\/IMAP \uff0c\u8fdb\u5165\u670d\u52a1\u5668\u8bbe\u7f6e\u9875\uff1a<\/p>\n<div>\n<div>\n<div><\/div>\n<div data-width=\\\"314\\\" data-height=\\\"235\\\"><img src=\\\"https:\/\/upload-images.jianshu.io\/upload_images\/3386108-ce24e2d9cb6bf4a8.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/314\/format\/webp\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/3386108-ce24e2d9cb6bf4a8.png\\\" data-original-width=\\\"314\\\" data-original-height=\\\"235\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"23918\\\" data-image-index=\\\"0\\\" \/><\/div>\n<\/div>\n<\/div>\n<p>\u8fdb\u5165\u670d\u52a1\u5668\u8bbe\u7f6e\u9875\u540e\uff0c\u786e\u4fdd\u5f00\u542f SMTP \u4e0e IMAP \u670d\u52a1\u3002\u8bbe\u7f6e\u9875\u7684\u6700\u4e0b\u9762\u5c31\u662f\u7f51\u6613\u90ae\u7bb1\u7684\u670d\u52a1\u5668\u5730\u5740\uff1a<\/p>\n<div>\n<div>\n<div><\/div>\n<div data-width=\\\"505\\\" data-height=\\\"658\\\"><img src=\\\"https:\/\/upload-images.jianshu.io\/upload_images\/3386108-e6dd003569fee900.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/505\/format\/webp\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/3386108-e6dd003569fee900.png\\\" data-original-width=\\\"505\\\" data-original-height=\\\"658\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"45031\\\" data-image-index=\\\"1\\\" \/><\/div>\n<\/div>\n<\/div>\n<p>\uff081\uff09SMTP<br \/>\n\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u4f7f\u7528\u7684\u534f\u8bae\u662f\u7b80\u5355\u90ae\u4ef6\u4f20\u8f93\u534f\u8bae\uff08 SMTP \uff0cSimple Mail Transfer Protocol\uff09\u3002\u5b83\u662f\u4e00\u79cd\u63d0\u4f9b\u53ef\u9760\u4e14\u6709\u6548\u7684\u7535\u5b50\u90ae\u4ef6\u4f20\u8f93\u7684\u534f\u8bae\u3002 SMTP \u662f\u5efa\u7acb\u5728 FTP \u6587\u4ef6\u4f20\u8f93\u670d\u52a1\u4e0a\u7684\u4e00\u79cd\u90ae\u4ef6\u670d\u52a1\uff0c\u4e3b\u8981\u7528\u4e8e\u7cfb\u7edf\u4e4b\u95f4\u7684\u90ae\u4ef6\u4fe1\u606f\u4f20\u9012\uff0c\u5e76\u63d0\u4f9b\u6709\u5173\u6765\u4fe1\u7684\u901a\u77e5\u3002 SMTP \u72ec\u7acb\u4e8e\u7279\u5b9a\u7684\u4f20\u8f93\u5b50\u7cfb\u7edf\uff0c\u4e14\u53ea\u9700\u8981\u53ef\u9760\u6709\u5e8f\u7684\u6570\u636e\u6d41\u4fe1\u9053\u652f\u6301\uff0c SMTP \u7684\u91cd\u8981\u7279\u6027\u4e4b\u4e00\u662f\u5176\u80fd\u8de8\u8d8a\u7f51\u7edc\u4f20\u8f93\u90ae\u4ef6\uff0c\u5373\u201c SMTP \u90ae\u4ef6\u4e2d\u7ee7 \u201d\u3002 \u4f7f\u7528 SMTP \uff0c\u53ef\u5b9e\u73b0\u76f8\u540c\u7f51\u7edc\u5904\u7406\u8fdb\u7a0b\u4e4b\u95f4\u7684\u90ae\u4ef6\u4f20\u8f93\uff0c\u4e5f\u53ef\u901a\u8fc7\u4e2d\u7ee7\u5668\u6216\u7f51\u5173\u5b9e\u73b0\u67d0\u5904\u7406\u8fdb\u7a0b\u4e0e\u5176\u4ed6\u7f51\u7edc\u4e4b\u95f4\u7684\u90ae\u4ef6\u4f20\u8f93\u3002<br \/>\n\uff082\uff09IMAP<br \/>\nIMAP\uff08Internet Mail Access Protocol\uff09\u4ee5\u524d\u79f0\u4f5c\u4ea4\u4e92\u90ae\u4ef6\u8bbf\u95ee\u534f\u8bae\uff08Interactive Mail Access Protocol\uff09\uff0c\u662f\u4e00\u4e2a\u5e94\u7528\u5c42\u534f\u8bae\u3002IMAP\u662f\u65af\u5766\u798f\u5927\u5b66\u57281986\u5e74\u5f00\u53d1\u7684\u4e00\u79cd\u90ae\u4ef6\u83b7\u53d6\u534f\u8bae\u3002\u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u90ae\u4ef6\u5ba2\u6237\u7aef\u53ef\u4ee5\u901a\u8fc7\u8fd9\u79cd\u534f\u8bae\u4ece\u90ae\u4ef6\u670d\u52a1\u5668\u4e0a\u83b7\u53d6\u90ae\u4ef6\u7684\u4fe1\u606f\uff0c\u4e0b\u8f7d\u90ae\u4ef6\u7b49\u3002\u5f53\u524d\u7684\u6743\u5a01\u5b9a\u4e49\u662fRFC3501\u3002IMAP\u534f\u8bae\u8fd0\u884c\u5728TCP\/IP\u534f\u8bae\u4e4b\u4e0a\uff0c\u4f7f\u7528\u7684\u7aef\u53e3\u662f143\u3002<br \/>\n\uff083\uff09POP3<br \/>\nPOP3\uff0c\u5168\u540d\u4e3a\u201cPost Office Protocol &#8211; Version 3\u201d\uff0c\u5373\u201c\u90ae\u5c40\u534f\u8bae\u7248\u672c3\u201d\u3002\u662fTCP\/IP\u534f\u8bae\u65cf\u4e2d\u7684\u4e00\u5458\uff0c\u7531RFC1939 \u5b9a\u4e49\u3002\u672c\u534f\u8bae\u4e3b\u8981\u7528\u4e8e\u652f\u6301\u4f7f\u7528\u5ba2\u6237\u7aef\u8fdc\u7a0b\u7ba1\u7406\u5728\u670d\u52a1\u5668\u4e0a\u7684\u7535\u5b50\u90ae\u4ef6\u3002\u63d0\u4f9b\u4e86SSL\u52a0\u5bc6\u7684POP3\u534f\u8bae\u88ab\u79f0\u4e3aPOP3S\u3002<br \/>\nPOP \u534f\u8bae\u652f\u6301 \u201c \u79bb\u7ebf \u201d \u90ae\u4ef6\u5904\u7406\u3002\u5176\u5177\u4f53\u8fc7\u7a0b\u662f\uff1a\u90ae\u4ef6\u53d1\u9001\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u7535\u5b50\u90ae\u4ef6\u5ba2\u6237\u7aef\u8c03\u7528\u90ae\u4ef6\u5ba2\u6237\u673a\u7a0b\u5e8f\u4ee5\u8fde\u63a5\u670d\u52a1\u5668\uff0c\u5e76\u4e0b\u8f7d\u6240\u6709\u672a\u9605\u8bfb\u7684\u7535\u5b50\u90ae\u4ef6\u3002\u8fd9\u79cd\u79bb\u7ebf\u8bbf\u95ee\u6a21\u5f0f\u662f\u4e00\u79cd\u5b58\u50a8\u8f6c\u53d1\u670d\u52a1\uff0c\u5c06\u90ae\u4ef6\u4ece\u90ae\u4ef6\u670d\u52a1\u5668\u7aef\u9001\u5230\u4e2a\u4eba\u7ec8\u7aef\u673a\u5668\u4e0a\uff0c\u4e00\u822c\u662f PC \u673a\u6216 MAC \u3002 \u4e00\u65e6\u90ae\u4ef6\u53d1\u9001\u5230 PC \u673a\u6216 MAC \u4e0a\uff0c\u90ae\u4ef6\u670d\u52a1\u5668\u4e0a\u7684\u90ae\u4ef6\u5c06\u4f1a\u88ab\u5220\u9664\u3002\u4f46 POP 3\u90ae\u4ef6\u670d\u52a1\u5668\u5927\u90fd\u53ef\u4ee5 \u201c \u53ea\u4e0b\u8f7d\u90ae\u4ef6\uff0c\u670d\u52a1\u5668\u7aef\u5e76\u4e0d\u5220\u9664 \u201d \uff0c\u4e5f\u5c31\u662f\u6539\u8fdb\u7684 POP 3\u534f\u8bae\u3002<\/p>\n<hr \/>\n<p>IMAP \u4e0e POP3 \u534f\u8bae\u7684\u4e3b\u8981\u533a\u522b\u662f\u7528\u6237\u53ef\u4ee5\u4e0d\u7528\u628a\u6240\u6709\u7684\u90ae\u4ef6\u5168\u90e8\u4e0b\u8f7d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5ba2\u6237\u7aef\u76f4\u63a5\u5bf9\u670d\u52a1\u5668\u4e0a\u7684\u90ae\u4ef6\u8fdb\u884c\u64cd\u4f5c\u3002\u6240\u4ee5\u76f8\u5bf9\u6765\u8bf4\uff0cIMAP \u534f\u8bae\u66f4\u5148\u8fdb\u3002<\/p>\n<h2>2 \u53d1\u9001\u7535\u5b50\u90ae\u4ef6<\/h2>\n<p>\uff081\uff09\u521b\u5efa SMTP \u5bf9\u8c61<br \/>\n\u9996\u5148\u521b\u5efa\u4e00\u4e2a SMTP \u5bf9\u8c61\uff0c\u5165\u53c2\u4e3a 163 \u90ae\u7bb1\u5730\u5740\u4e0e\u7aef\u53e3\u53f7<\/p>\n<div>\n<pre>smtp_obj = smtplib.SMTP(\\'smtp.163.com\\', 25);\n<\/pre>\n<\/div>\n<p>\uff082\uff09\u5efa\u7acb\u8fde\u63a5<\/p>\n<div>\n<pre>response = smtp_obj.ehlo()\nlogging.info(\\'ehlo() -&gt; %s\\', response)\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<div>\n<pre>INFO - ehlo() -&gt; (250, b\\'mail\\\\nPIPELINING\\\\nAUTH LOGIN PLAIN\\\\nAUTH=LOGIN PLAIN\\\\ncoremail xxx\\\\nSTARTTLS\\\\n8BITMIME\\')\n<\/pre>\n<\/div>\n<p>\u5f97\u5230 SMTP \u5bf9\u8c61\u540e\uff0c\u8c03\u7528 ehlo() \u65b9\u6cd5\uff0c\u8fde\u63a5 SMTP \u7535\u5b50\u90ae\u4ef6\u670d\u52a1\u5668,\u3002<br \/>\n250 \u5c31\u8868\u793a\u8fde\u63a5\u6210\u529f\u3002<br \/>\nSMTP \u534f\u8bae\u6709\u4ee5\u4e0b\u8fd9\u4e9b\u54cd\u5e94\u7801\uff0c\u6bcf\u4e2a\u54cd\u5e94\u7801\u7684\u5177\u4f53\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u54cd\u5e94\u7801<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>501<\/td>\n<td>\u53c2\u6570\u683c\u5f0f\u9519\u8bef<\/td>\n<\/tr>\n<tr>\n<td>502<\/td>\n<td>\u547d\u4ee4\u4e0d\u53ef\u5b9e\u73b0<\/td>\n<\/tr>\n<tr>\n<td>503<\/td>\n<td>\u9519\u8bef\u7684\u547d\u4ee4\u5e8f\u5217<\/td>\n<\/tr>\n<tr>\n<td>504<\/td>\n<td>\u547d\u4ee4\u53c2\u6570\u4e0d\u53ef\u5b9e\u73b0<\/td>\n<\/tr>\n<tr>\n<td>211<\/td>\n<td>\u7cfb\u7edf\u72b6\u6001\u6216\u7cfb\u7edf\u5e2e\u52a9\u54cd\u5e94<\/td>\n<\/tr>\n<tr>\n<td>214<\/td>\n<td>\u5e2e\u52a9\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td>220<\/td>\n<td>\uff1cdomain\uff1e\u670d\u52a1\u5c31\u7eea<\/td>\n<\/tr>\n<tr>\n<td>221<\/td>\n<td>\uff1cdomain\uff1e\u670d\u52a1\u5173\u95ed<\/td>\n<\/tr>\n<tr>\n<td>421<\/td>\n<td>\uff1cdomain\uff1e\u670d\u52a1\u672a\u5c31\u7eea\uff0c\u5173\u95ed\u4f20\u8f93\u4fe1\u9053<\/td>\n<\/tr>\n<tr>\n<td>250<\/td>\n<td>\u64cd\u4f5c\u5b8c\u6210<\/td>\n<\/tr>\n<tr>\n<td>251<\/td>\n<td>\u7528\u6237\u975e\u672c\u5730\uff0c\u5c06\u8f6c\u53d1\u5230\uff1cforward-path\uff1e<\/td>\n<\/tr>\n<tr>\n<td>450<\/td>\n<td>\u8981\u6c42\u7684\u64cd\u4f5c\u672a\u5b8c\u6210\uff0c\u6536\u4fe1\u7aef\u65e0\u6b64\u8d26\u6237<\/td>\n<\/tr>\n<tr>\n<td>550<\/td>\n<td>\u8981\u6c42\u7684\u64cd\u4f5c\u672a\u5b8c\u6210\uff0c\u90ae\u7bb1\u4e0d\u53ef\u7528<\/td>\n<\/tr>\n<tr>\n<td>451<\/td>\n<td>\u653e\u5f03\u8981\u6c42\u7684\u64cd\u4f5c\uff1b\u5904\u7406\u8fc7\u7a0b\u4e2d\u51fa\u9519<\/td>\n<\/tr>\n<tr>\n<td>551<\/td>\n<td>\u7528\u6237\u975e\u672c\u5730\uff0c\u8bf7\u5c1d\u8bd5\uff1cforward-path\uff1e<\/td>\n<\/tr>\n<tr>\n<td>452<\/td>\n<td>\u7cfb\u7edf\u5b58\u50a8\u4e0d\u8db3\uff0c\u8981\u6c42\u7684\u64cd\u4f5c\u672a\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>552<\/td>\n<td>\u8fc7\u91cf\u7684\u5b58\u50a8\u5206\u914d\uff0c\u8981\u6c42\u7684\u64cd\u4f5c\u672a\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>553<\/td>\n<td>\u90ae\u7bb1\u540d\u4e0d\u53ef\u7528\uff0c\u8981\u6c42\u7684\u64cd\u4f5c\u672a\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>554<\/td>\n<td>\u64cd\u4f5c\u5931\u8d25<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\uff083\uff09TLS \u52a0\u5bc6<br \/>\n\u7f51\u6613\u90ae\u7bb1\u7684 POP3\/SMTP\/IMAP \u670d\u52a1\u5168\u90e8\u652f\u6301 SSL \u8fde\u63a5\u3002<br \/>\n\u5b89\u5168\u4f20\u8f93\u5c42\u534f\u8bae\uff08TLS\uff09\u7528\u4e8e\u5728\u4e24\u4e2a\u901a\u4fe1\u5e94\u7528\u7a0b\u5e8f\u4e4b\u95f4\u63d0\u4f9b\u4fdd\u5bc6\u6027\u548c\u6570\u636e\u5b8c\u6574\u6027\u3002<br \/>\n\u4f20\u8f93\u5c42\u5b89\u5168\u6027\u534f\u8bae\uff08 Transport Layer Security \uff0c\u7f29\u5199\u4f5c TLS \uff09\uff0c\u53ca\u5176\u524d\u8eab\u5b89\u5168\u5957\u63a5\u5c42\uff08 Secure Sockets Layer \uff0c\u7f29\u5199\u4f5c SSL \uff09\u662f\u4e00\u79cd\u5b89\u5168\u534f\u8bae\uff0c\u76ee\u7684\u662f\u4e3a\u4e92\u8054\u7f51\u901a\u4fe1\u63d0\u4f9b\u5b89\u5168\u53ca\u6570\u636e\u5b8c\u6574\u6027\u4fdd\u969c\u3002\u7f51\u666f\u516c\u53f8\uff08 Netscape \uff09\u5728 1994 \u5e74\u63a8\u51fa\u9996\u7248\u7f51\u9875\u6d4f\u89c8\u5668\uff0c\u7f51\u666f\u5bfc\u822a\u8005\u65f6\uff0c\u63a8\u51fa HTTPS \u534f\u8bae\uff0c\u4ee5 SSL \u8fdb\u884c\u52a0\u5bc6\uff0c\u8fd9\u662f SSL \u7684\u8d77\u6e90 \u3002IETF \u5c06 SSL \u8fdb\u884c\u6807\u51c6\u5316\uff0c 1999 \u5e74\u516c\u5e03\u7b2c\u4e00\u7248 TLS \u6807\u51c6\u6587\u4ef6\u3002\u968f\u540e\u53c8\u516c\u5e03 RFC5246 \uff08 2008 \u5e748\u6708\uff09\u4e0e RFC6176 \uff08 2011 \u5e743\u6708\uff09\u3002\u5728\u6d4f\u89c8\u5668 \u3001 \u90ae\u7bb1 \u3001 \u5373\u65f6\u901a\u4fe1 \u3001 VoIP \u3001 \u7f51\u7edc\u4f20\u771f\u7b49\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u5e7f\u6cdb\u652f\u6301\u8fd9\u4e2a\u534f\u8bae\u3002\u4e3b\u8981\u7684\u7f51\u7ad9\uff0c\u5982Google \u3001 Facebook\u7b49\u4e5f\u4ee5\u8fd9\u4e2a\u534f\u8bae\u6765\u521b\u5efa\u5b89\u5168\u8fde\u7ebf\uff0c\u53d1\u9001\u6570\u636e\u3002\u76ee\u524d\u5df2\u6210\u4e3a\u4e92\u8054\u7f51\u4e0a\u4fdd\u5bc6\u901a\u4fe1\u7684\u5de5\u4e1a\u6807\u51c6\u3002<\/p>\n<div>\n<pre>response = smtp_obj.starttls()\nlogging.info(\\'starttls() -&gt; %s\\\\n\\', response)\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<div>\n<pre>INFO - starttls() -&gt; (220, b\\'Ready to start TLS\\')\n<\/pre>\n<\/div>\n<p>\u54cd\u5e94\u7801 220 \u8868\u793a\u670d\u52a1\u5668\u5df2\u5f00\u542f TLS \u52a0\u5bc6\u6a21\u5f0f\u3002<br \/>\n\uff084\uff09\u767b\u9646 SMTP \u670d\u52a1\u5668<br \/>\n\u5efa\u7acb TLS \u52a0\u5bc6\u8fde\u63a5\u540e\uff0c\u5c31\u53ef\u4ee5\u8c03\u7528 login() \u65b9\u6cd5\uff0c\u7528\u90ae\u7bb1\u8d26\u6237\u540d\u4e0e\u5bc6\u7801\u8fdb\u884c\u767b\u5f55\u64cd\u4f5c\u3002\u5efa\u8bae\u4f7f\u7528 input() \uff0c\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u8f93\u5165\u5bc6\u7801\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\uff0c\u907f\u514d\u56e0\u4e3a\u6e90\u4ee3\u7801\u6cc4\u9732\uff0c\u5bfc\u81f4\u5bc6\u7801\u5916\u6cc4\u3002<\/p>\n<div>\n<pre>email_address = xxx@xxx.com\\'\npwd = input(\\'please input your password:\\')\nresponse = smtp_obj.login(email_address, pwd)\nlogging.info(\\'\\\\nlogin() -&gt; %s\\', response)\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<div>\n<pre>please input your password:&gt; xxx\nINFO -\nlogin() -&gt; (235, b\\'Authentication successful\\')\n<\/pre>\n<\/div>\n<p>login \u65b9\u6cd5\u63a5\u6536\u8d26\u53f7\u4e0e\u5bc6\u7801\u4f5c\u4e3a\u5165\u53c2\u3002\u8fd9\u91cc\u8fd4\u56de 235 \u8868\u793a\u8ba4\u8bc1\u6210\u529f\u3002\u5982\u679c\u5bc6\u7801\u4e0d\u6b63\u786e\uff0c Python \u4f1a\u629b\u51fa smtplib.SMTPAuthenticationError \u5f02\u5e38\u3002<br \/>\n\uff085\uff09\u5b9a\u4e49\u53d1\u9001\u5185\u5bb9<\/p>\n<div>\n<pre>msg = MIMEMultipart()\nmsg[\\\"From\\\"] = email_address\nto_mail_address = yyy@yyy.com\\'\nmsg[\\'To\\'] = to_mail_address\nmsg[\\'Subject\\'] = \\'\u786e\u8ba4\u300aSpring Cloud\u5fae\u670d\u52a1\u67b6\u6784\u300b\\'\ncontent = MIMEText(\\'\u6536\u5230\u8fd9\u672c\u4e66\u540e\uff0c&lt;b&gt;\u8bf7\u56de\u590d\u4e0b&lt;\/b&gt;\\', \\'html\\', \\'utf-8\\')\nmsg.attach(content)\n<\/pre>\n<\/div>\n<p>\u5148\u521b\u5efa MIMEMultipart \u5bf9\u8c61\uff0c\u7136\u540e\u5b9a\u4e49\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u952e<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>From<\/td>\n<td>\u53d1\u9001\u7aef\u90ae\u7bb1\u5730\u5740\u3002<\/td>\n<\/tr>\n<tr>\n<td>To<\/td>\n<td>\u63a5\u6536\u7aef\u90ae\u7bb1\u5730\u5740\u3002<\/td>\n<\/tr>\n<tr>\n<td>Subject<\/td>\n<td>\u90ae\u7bb1\u6807\u9898\u3002<\/td>\n<\/tr>\n<tr>\n<td>content<\/td>\n<td>\u90ae\u7bb1\u5185\u5bb9\uff0cHTML \u683c\u5f0f\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\uff086\uff09\u53d1\u9001\u90ae\u4ef6<\/p>\n<div>\n<pre>response = smtp_obj.sendmail(email_address, to_mail_address, msg.as_string())\nlogging.info(\\'sendmail() -&gt; %s\\', response)\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<div>\n<pre>INFO - sendmail() -&gt; {}\n<\/pre>\n<\/div>\n<p>\u7136\u540e\u8c03\u7528 sendmail()\u65b9\u6cd5\u6765\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002 sendmail() \u7684\u8fd4\u56de\u503c\u662f\u4e00\u4e2a\u5b57\u5178\u7c7b\u578b\u3002\u5982\u679c\u53d1\u9001\u5931\u8d25\uff0c\u90a3\u4e48\u8be5\u5b57\u5178\u5c31\u4f1a\u8fd4\u56de\u5305\u542b\u5931\u8d25\u6536\u4ef6\u4eba\u7684\u952e\u503c\u5bf9\u4fe1\u606f\uff1b\u5982\u679c\u53d1\u9001\u6210\u529f\uff0c\u90a3\u4e48\u8be5\u5b57\u5178\u4e3a\u7a7a\u3002<br \/>\n\uff087\uff09\u65ad\u5f00\u8fde\u63a5<\/p>\n<div>\n<pre>response = smtp_obj.quit()\nlogging.info(\\'quit() -&gt; %s\\', response)\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<div>\n<pre>INFO - quit() -&gt; (221, b\\'Bye\\')\n<\/pre>\n<\/div>\n<p>\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u540e\uff0c\u8c03\u7528 quit()\u65b9\u6cd5\uff0c\u65ad\u5f00\u4e0e SMTP \u670d\u52a1\u5668\u7684\u8fde\u63a5\u3002 \u54cd\u5e94\u7801 221 \u8868\u793a\u4f1a\u8bdd\u7ed3\u675f\u3002<\/p>\n<hr \/>\n<p>\u5b8c\u6574\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<div>\n<pre>import logging\nimport smtplib\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\nlogging.basicConfig(level=logging.DEBUG, format=\\'%(levelname)s - %(message)s\\')\n\\'\\'\\'\nsend email\n@author Deniro Lee\n\\'\\'\\'\nprint(\\'$$$\\')\nsmtp_obj = smtplib.SMTP(\\'smtp.163.com\\', 25);\nresponse = smtp_obj.ehlo()\nlogging.info(\\'ehlo() -&gt; %s\\', response)\nresponse = smtp_obj.starttls()\nlogging.info(\\'starttls() -&gt; %s\\\\n\\', response)\nemail_address = xxx@xxx.com\\'\npwd = input(\\'please input your password:\\')\nresponse = smtp_obj.login(email_address, pwd)\nlogging.info(\\'\\\\nlogin() -&gt; %s\\', response)\nmsg = MIMEMultipart()\nmsg[\\\"From\\\"] = email_address\nto_mail_address = yyy@yyy.com\\'\nmsg[\\'To\\'] = to_mail_address\nmsg[\\'Subject\\'] = \\'\u786e\u8ba4\u300aSpring Cloud\u5fae\u670d\u52a1\u67b6\u6784\u300b\\'\ncontent = MIMEText(\\'\u6536\u5230\u8fd9\u672c\u4e66\u540e\uff0c&lt;b&gt;\u8bf7\u56de\u590d\u4e0b&lt;\/b&gt;\\', \\'html\\', \\'utf-8\\')\nmsg.attach(content)\nresponse = smtp_obj.sendmail(email_address, to_mail_address, msg.as_string())\nlogging.info(\\'sendmail() -&gt; %s\\', response)\nresponse = smtp_obj.quit()\nlogging.info(\\'quit() -&gt; %s\\', response)\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<div>\n<pre>INFO - ehlo() -&gt; (250, b\\'mail\\\\nPIPELINING\\\\nAUTH LOGIN PLAIN\\\\nAUTH=LOGIN PLAIN\\\\ncoremail xxx\\\\nSTARTTLS\\\\n8BITMIME\\')\nINFO - starttls() -&gt; (220, b\\'Ready to start TLS\\')\nplease input your password:&gt; xxx\nINFO -\nlogin() -&gt; (235, b\\'Authentication successful\\')\nINFO - sendmail() -&gt; {}\nINFO - quit() -&gt; (221, b\\'Bye\\')\n<\/pre>\n<\/div>\n<p>\u6253\u5f00\u53d1\u9001\u76ee\u6807\u90ae\u7bb1\u540e\uff0c\u5c31\u4f1a\u770b\u5230\u521a\u521a\u53d1\u51fa\u7684\u8fd9\u5c01\u90ae\u4ef6\uff1a<br \/>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 Python \u7684 smtplib \u6a21\u5757\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u53d1\u9001\u90ae\u4ef6\u3002 1 \u7535\u5b50\u90ae\u4ef6\u670d\u52a1\u5668 \u5982\u679c\u662f\u7f51\u6613 163 \u90ae &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1637\"> <span class=\"screen-reader-text\">\u4f7f\u7528 Python \u53d1\u9001\u7535\u5b50\u90ae\u4ef6<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[106,126],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"\u4f7f\u7528 Python \u7684 smtplib \u6a21\u5757\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u53d1\u9001\u90ae\u4ef6\u3002 1 \u7535\u5b50\u90ae\u4ef6\u670d\u52a1\u5668 \u5982\u679c\u662f\u7f51\u6613 163 \u90ae&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1637"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1637"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1637\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1637"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}