{"id":461,"date":"2021-09-08T11:28:25","date_gmt":"2021-09-08T02:28:25","guid":{"rendered":"https:\/\/rfsec.ddns.net\/db\/?p=461"},"modified":"2021-09-10T08:35:45","modified_gmt":"2021-09-09T23:35:45","slug":"python%e3%81%8b%e3%82%89ssl%e3%81%a7%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%92%e9%80%81%e4%bf%a1","status":"publish","type":"post","link":"https:\/\/rfsec.ddns.net\/db\/?p=461","title":{"rendered":"Python\u304b\u3089SSL\u3067\u30e1\u30fc\u30eb\u3092\u9001\u4fe1"},"content":{"rendered":"\n<p>STARTTLS\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import smtplib, ssl\n\n#\u9001\u4fe1\u306b\u5229\u7528\u3059\u308b\u30e1\u30fc\u30eb\u30b5\u30fc\u30d0\u306e\u8a2d\u5b9a\uff08\u30d7\u30ed\u30d0\u30a4\u30c0\u30fc\u306e\u30e1\u30fc\u30eb\u30a2\u30ab\u30a6\u30f3\u30c8\u3001SMTP\u30b5\u30fc\u30d0\u30fc\uff09\nusername= &quot;aaa@bbb.ccc.ddd&quot;\npassword=  &quot;xxxxx&quot;\nmail_server=&quot;smtp.eeee.ffff&quot; # SMTP Server\nport=465\n\n#\u507d\u88c5\u9001\u4fe1\u5143 \nfake_from= &quot;donaldtrump@gmail.com&quot;\nfake_name= &quot;Donald Trump&quot;\n\n#\u30e1\u30fc\u30eb\u306e\u5b9b\u5148\nto_email= &#39;hoge@hoge.hoge&#39;\nto_name= &#39;hoge@hoge.hoge&#39;\n\nsubject= &quot;Bonjour&quot;\ncontent= &quot;This is the fbi. OPEN UP&quot;\nmessage= f&quot;From: {fake_name} &lt;{fake_from}&gt;\\nTo: {to_name} &lt;{to_email}&gt;\\nSubject: {subject}\\n\\n{content}&quot;\nserver = smtplib.SMTP_SSL(mail_server,port, context=ssl.create_default_context())\nserver.login(username, password)\nserver.sendmail(username, to_email, message.encode())\nserver.close()<\/code><\/pre><\/div>\n\n\n\n<p>MIME\u6a5f\u80fd\u3092\u4ed8\u52a0\u3057\u3066\u3001\u65e5\u672c\u8a9e\u30fbHTML\u306e\u30e1\u30fc\u30eb\u3092\u9001\u4fe1<\/p>\n\n\n\n<p>\u901a\u4fe1\u306e\u30c7\u30d0\u30c3\u30b0\u60c5\u5831\u3092\u8868\u793a\u3059\u308b\u306b\u306f\u3000<strong>server.set_debuglevel(True)<\/strong>\u3000\u3092\u633f\u5165<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><\/h1>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import smtplib,ssl\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\nsmtp_host = &#39;mail.xxx.xxx&#39; #Mail\u30b5\u30fc\u30d0\u3092\u6307\u5b9a\nsmtp_port = 465\nsmtp_account_id = &#39;hogehoge&#39; #\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u6307\u5b9a\nsmtp_account_pass = &#39;xxxxxxx&#39; #\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b\nfrom_mail = &quot;hoge &lt;hoge@xxxx.xxx.xx&gt;&quot;  # \u9001\u4fe1\u5143\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\nto_mail = &quot;HOGE &lt;HOGE@xxxx.xxx&gt;&quot;  # \u9001\u4fe1\u5148\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\nmsg = MIMEMultipart(&#39;alternative&#39;)\nmsg[&#39;Subject&#39;] = &quot;\u30bf\u30a4\u30c8\u30eb&quot; #\u4ef6\u540d\u3092\u5165\u529b\nmsg[&#39;From&#39;] = from_mail\nmsg[&#39;To&#39;] = to_mail\ntext = &quot;\u9001\u4fe1\u30c6\u30b9\u30c8\u3067\u3059\u3002.n\u30de\u30eb\u30c1\u30d1\u30fc\u30c8\u3067\u9001\u3063\u3066\u3044\u307e\u3059\u3002.n\u3069\u3046\u3067\u3059\u304b\uff1f&quot;\nhtml = &quot;&quot;&quot;\n&lt;html&gt;\n  &lt;head&gt;&lt;\/head&gt;\n  &lt;body&gt;\n    &lt;p style=&#39;font-size:16.0pt;font-family:\u6e38\u30b4\u30b7\u30c3\u30af&#39;&gt;\u9001\u4fe1\u30c6\u30b9\u30c8\u3067\u3059\u3002&lt;\/p&gt;\n    &lt;p&gt;\u30de\u30eb\u30c1\u30d1\u30fc\u30c8\u3067\u9001\u3063\u3066\u3044\u307e\u3059\u3002&lt;\/p&gt;\n    &lt;p&gt;\u3069\u3046\u3067\u3059\u304b\uff1f&lt;\/p&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;\n&quot;&quot;&quot;\n\npart1 = MIMEText(text, &#39;plain&#39;)\npart2 = MIMEText(html, &#39;html&#39;)\nmsg.attach(part1)\nmsg.attach(part2)\n\nserver = smtplib.SMTP_SSL(smtp_host, smtp_port, context=ssl.create_default_context())\n#server.set_debuglevel(True)\nserver.login(smtp_account_id, smtp_account_pass)\nserver.sendmail(from_mail, to_mail, msg.as_string())\nserver.quit()\nprint(&#39;Done.&#39;)<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>STARTTLS\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408 MIME\u6a5f\u80fd\u3092\u4ed8\u52a0\u3057\u3066\u3001\u65e5\u672c\u8a9e\u30fbHTML\u306e\u30e1\u30fc\u30eb\u3092\u9001\u4fe1 \u901a\u4fe1\u306e\u30c7\u30d0\u30c3\u30b0\u60c5\u5831\u3092\u8868\u793a\u3059\u308b\u306b\u306f\u3000server.set_debuglevel(True)\u3000\u3092\u633f\u5165<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8,3],"tags":[],"class_list":["post-461","post","type-post","status-publish","format-standard","hentry","category-security","category-network"],"featured_image_src":null,"author_info":{"display_name":"mars","author_link":"https:\/\/rfsec.ddns.net\/db\/?author=1"},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=461"}],"version-history":[{"count":6,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/461\/revisions"}],"predecessor-version":[{"id":478,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/461\/revisions\/478"}],"wp:attachment":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}