﻿{"id":466,"date":"2021-08-21T11:44:34","date_gmt":"2021-08-21T03:44:34","guid":{"rendered":"https:\/\/dt9025a.xyz\/?p=466"},"modified":"2022-04-24T21:01:08","modified_gmt":"2022-04-24T13:01:08","slug":"python%e4%bd%bf%e7%94%a8smtp%e5%8f%91%e4%bf%a1%e5%a4%b1%e8%b4%a5","status":"publish","type":"post","link":"https:\/\/dt9025a.top\/?p=466","title":{"rendered":"Python\u4f7f\u7528SMTP\u53d1\u4fe1\u5931\u8d25"},"content":{"rendered":"\n<p> \u4f7f\u7528\u4e86\u9b54\u6539\u540e\u7684<a rel=\"noreferrer noopener\" href=\"https:\/\/www.runoob.com\/python\/python-email.html\" target=\"_blank\">\u83dc\u9e1f\u6559\u7a0b<\/a>\u4e2d\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/usr\/bin\/python\n# -*- coding: UTF-8 -*-\n \nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.header import Header\n \n# \u7b2c\u4e09\u65b9 SMTP \u670d\u52a1\nmail_host=\"smtp.163.com\"  #\u8bbe\u7f6e\u670d\u52a1\u5668\nmail_user=\"XXXX\"    #\u7528\u6237\u540d\nmail_pass=\"XXXXXX\"   #\u53e3\u4ee4 \n \n \nsender = 'from@runoob.com'\nreceivers = 429240967@qq.com # \u63a5\u6536\u90ae\u4ef6\uff0c\u53ef\u8bbe\u7f6e\u4e3a\u4f60\u7684QQ\u90ae\u7bb1\u6216\u8005\u5176\u4ed6\u90ae\u7bb1\n \nmessage = MIMEText('Python \u90ae\u4ef6\u53d1\u9001\u6d4b\u8bd5...', 'plain', 'utf-8')\nmessage['From'] = Header(\"\u83dc\u9e1f\u6559\u7a0b\", 'utf-8')\nmessage['To'] =  Header(\"\u6d4b\u8bd5\", 'utf-8')\n \nsubject = 'Python SMTP \u90ae\u4ef6\u6d4b\u8bd5'\nmessage['Subject'] = Header(subject, 'utf-8')\n \n \ntry:\n    smtpObj = smtplib.SMTP_SSL() \n    smtpObj.connect(mail_host, 465)    # 25 \u4e3a SMTP \u7aef\u53e3\u53f7\n    smtpObj.login(mail_user,mail_pass)  \n    smtpObj.sendmail(sender, receivers, message.as_string())\n    print \"\u90ae\u4ef6\u53d1\u9001\u6210\u529f\"\nexcept smtplib.SMTPException:\n    print \"Error: \u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\"<\/pre>\n\n\n\n<p>\u4f46\u662f\u914d\u7f6e\u5b8c\u6210\u540e\u4e00\u76f4\u8f93\u51fa<code>Error: \u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6<\/code>\uff0c\u8fd9\u8ba9\u6211\u611f\u5230\u65e0\u8bed\u3002<\/p>\n\n\n\n<p>\u6253\u5f00<code>set_debuglevel(1)<\/code>\uff0c\u53d1\u73b0\u8fde\u63a5\u670d\u52a1\u5668\u3001\u767b\u5f55\u662f\u6ca1\u6709\u4e00\u70b9\u95ee\u9898\uff0c\u95ee\u9898\u51fa\u5728\u4e86\u53d1\u4ef6\u4e0a\u3002<\/p>\n\n\n\n<p>\u5e72\u6389<code>try<\/code>\u8bed\u53e5\u5757\uff0c\u9519\u8bef\u5f39\u51fa\u6765\u4e86\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"848\" height=\"68\" src=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2021\/08\/image-3.png\" alt=\"\" class=\"wp-image-467\" srcset=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2021\/08\/image-3.png 848w, https:\/\/dt9025a.top\/wp-content\/uploads\/2021\/08\/image-3-300x24.png 300w, https:\/\/dt9025a.top\/wp-content\/uploads\/2021\/08\/image-3-768x62.png 768w\" sizes=\"auto, (max-width: 848px) 100vw, 848px\" \/><\/figure><\/div>\n\n\n\n<p>\u8ddf\u7740\u94fe\u63a5\u70b9\u8fdb\u53bb\u4e00\u770b\uff0c\u53d1\u73b0\u662f\u88ab\u9000\u4fe1\u4e86\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"73\" src=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2021\/08\/image-4.png\" alt=\"\" class=\"wp-image-468\" srcset=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2021\/08\/image-4.png 695w, https:\/\/dt9025a.top\/wp-content\/uploads\/2021\/08\/image-4-300x32.png 300w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><\/figure><\/div>\n\n\n\n<p> \u6700\u540e\uff0c\u7ecf\u8fc7\u641c\u7d22\uff0c\u901a\u8fc7<a rel=\"noreferrer noopener\" href=\"https:\/\/www.cnblogs.com\/NolaLi\/p\/11098670.html\" target=\"_blank\">\u8fd9\u7bc7\u535a\u5ba2<\/a>\u89e3\u51b3\u4e86\u95ee\u9898\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u5c06From\u548cTo\u5b57\u6bb5\u76f4\u63a5\u4f7f\u7528\u53d1\u4ef6\u3001\u6536\u4ef6\u4eba\u5730\u5740\u5373\u53ef\nmessage['From'] = mail_user\nmessage['To'] = receivers<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u4e86\u9b54\u6539\u540e\u7684\u83dc\u9e1f\u6559\u7a0b\u4e2d\u7684\u4ee3\u7801\uff1a #!\/usr\/bin\/python # -*- coding: UTF-8 &#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/dt9025a.top\/?p=466\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-466","post","type-post","status-publish","format-standard","hentry","category-9"],"_links":{"self":[{"href":"https:\/\/dt9025a.top\/index.php?rest_route=\/wp\/v2\/posts\/466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dt9025a.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dt9025a.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dt9025a.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dt9025a.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=466"}],"version-history":[{"count":0,"href":"https:\/\/dt9025a.top\/index.php?rest_route=\/wp\/v2\/posts\/466\/revisions"}],"wp:attachment":[{"href":"https:\/\/dt9025a.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dt9025a.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dt9025a.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}