{"id":2495,"date":"2021-09-20T07:00:53","date_gmt":"2021-09-19T22:00:53","guid":{"rendered":"https:\/\/gb-j.com\/?p=2495"},"modified":"2021-09-17T14:27:59","modified_gmt":"2021-09-17T05:27:59","slug":"python-smtplib","status":"publish","type":"post","link":"https:\/\/gb-j.com\/column\/python-smtplib\/","title":{"rendered":"Cloud Functions \u3067\u3082\u4f7f\u3048\u308b Python \u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u30d1\u30c3\u30b1\u30fc\u30b8 smtplib"},"content":{"rendered":"<h1>Cloud Functions &#8211; Python<\/h1>\r\nPython \u306f\u6a19\u6e96\u3067\u591a\u7a2e\u591a\u69d8\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002\r\n\u3057\u304b\u3057 Cloud Functions \u3067\u306f\u5229\u7528\u3067\u304d\u306a\u3044\u3082\u306e\u3084\u3001\u6a5f\u80fd\u304c\u5236\u9650\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u304c\u3042\u308a\u3001\u3057\u304b\u3082\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u3088\u3063\u3066\u5229\u7528\u53ef\u80fd\u6709\u7121\u304c\u7570\u306a\u3063\u3066\u3044\u305f\u308a\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u904e\u53bb\u306b\u306f\u753b\u50cf\u7cfb\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u304c Cloud Functions \u3067\u5229\u7528\u3067\u304d\u306a\u304b\u3063\u305f\u305f\u3081\u3001\u6025\u907d\u753b\u50cf\u51e6\u7406\u7528\u306e\u30b5\u30fc\u30d0\u3092\u7528\u610f\u3057\u305f\u3053\u3068\u3082\u3042\u308a\u307e\u3057\u305f\u3002\r\n\u4eca\u56de Cloud Functions \u3088\u308a\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u5fc5\u8981\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u52d5\u4f5c\u78ba\u8a8d\u3092\u542b\u3081\u3066 Python \u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u30d1\u30c3\u30b1\u30fc\u30b8 smtplib \u3092\u5229\u7528\u3057\u3066\u307f\u305f\u306e\u3067\u7d39\u4ecb\u3057\u307e\u3059\u3002\r\n<h1>\u65e5\u672c\u8a9e\u306e\u30e1\u30fc\u30eb\u3092\u9001\u4fe1<\/h1>\r\nsmtplib \u306f Python \u3067\u624b\u8efd\u306b\u5229\u7528\u3067\u304d\u307e\u3059\u304c\u3001\u65e5\u672c\u8a9e\u3092\u9001\u308d\u3046\u3068\u3059\u308b\u3068\u30e1\u30fc\u30eb\u30bf\u30a4\u30c8\u30eb\u3068\u30e1\u30fc\u30eb\u672c\u6587\u306b\u6587\u5b57\u30b3\u30fc\u30c9\u306e\u8a2d\u5b9a\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002\u4e00\u822c\u7684\u306b\u306f UTF-8 \u3092\u5229\u7528\u3059\u308c\u3070\u3044\u3044\u3067\u3057\u3087\u3046\u3002\u4e0b\u8a18\u3067\u306f\u305d\u306e\u8a2d\u5b9a\u65b9\u6cd5\u3082\u4f75\u305b\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002\r\n<h1>SMTP \u30b5\u30fc\u30d0 ( Gmail )<\/h1>\r\n\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u306b\u306f SMTP \u30b5\u30fc\u30d0\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002\u4eca\u56de\u306f\u7121\u6599\u3067\u5229\u7528\u3067\u304d\u308b Gmail \u3092\u5229\u7528\u3057\u305f\u30b1\u30fc\u30b9\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002\u305f\u3060\u305d\u306e\u305f\u3081\u306b\u306f Gmail \u3067\u306e\u8a2d\u5b9a\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u5b89\u5168\u6027\u306e\u4f4e\u3044\u30a2\u30d7\u30ea\u3092\u8a31\u53ef\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u4e0a\u30aa\u30b9\u30b9\u30e1\u3067\u304d\u306a\u3044\u306e\u3067\u3053\u3053\u3067\u306f\u7d39\u4ecb\u3057\u307e\u305b\u3093\u3002\uff09\r\n<ol>\r\n \t<li>\u4e0b\u8a18\u3088\u308a Google \u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u3092\u958b\u304f\r\n<a href=\"https:\/\/myaccount.google.com\/security?authuser=0\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https:\/\/myaccount.google.com\/security<\/a><\/li>\r\n \t<li>2\u6bb5\u968e\u8a8d\u8a3c\u30d7\u30ed\u30bb\u30b9\u3092\u30aa\u30f3\u306b\u3059\u308b\r\n2\u6bb5\u968e\u8a8d\u8a3c\u30d7\u30ed\u30bb\u30b9\u3092\u30aa\u30f3\u306b\u3057\u3001\u30a6\u30a3\u30b6\u30fc\u30c9\u306b\u5f93\u3063\u3066\u8a2d\u5b9a\u3092\u884c\u3063\u3066\u304f\u3060\u3055\u3044<a href=\"https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_03.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2499\" src=\"https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_03.png\" alt=\"\" width=\"1065\" height=\"852\" srcset=\"https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_03.png 1065w, https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_03-300x240.png 300w, https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_03-1024x819.png 1024w, https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_03-768x614.png 768w\" sizes=\"(max-width: 1065px) 100vw, 1065px\" \/><\/a><\/li>\r\n \t<li>\u30a2\u30d7\u30ea\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u751f\u6210\u3059\u308b\r\n\u901a\u5e38\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u3068\u304d\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u3068\u306f\u5225\u306b\u3001\u30a2\u30d7\u30ea\u304b\u3089\u5229\u7528\u3059\u308b\u305f\u3081\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u751f\u6210\u3057\u307e\u3059\u3002\r\n\u30fb\u30a2\u30d7\u30ea\u3092\u9078\u629e: \u30e1\u30fc\u30eb\r\n\u30fb\u30c7\u30d0\u30a4\u30b9\u3092\u9078\u629e: \u305d\u306e\u307b\u304b\uff08\u540d\u524d\u3092\u5165\u529b\uff09<a href=\"https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_33.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2500\" src=\"https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_33.png\" alt=\"\" width=\"1065\" height=\"852\" srcset=\"https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_33.png 1065w, https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_33-300x240.png 300w, https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_33-1024x819.png 1024w, https:\/\/gb-j.com\/wp-content\/uploads\/2021\/09\/2021-09-17_14h04_33-768x614.png 768w\" sizes=\"(max-width: 1065px) 100vw, 1065px\" \/><\/a><\/li>\r\n<\/ol>\r\n\u751f\u6210\u3055\u308c\u305f\u30a2\u30d7\u30ea\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u305d\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5229\u7528\u3057\u307e\u3059\u3002\r\n<h1>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h1>\r\n\u305d\u308c\u3067\u306f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u793a\u3057\u307e\u3059\u3002\r\n<pre>from email.header import Header\r\nfrom email.mime.text import MIMEText\r\nimport smtplib\r\n\r\nSENDER_EMAIL = 'SENDER@MAIL.ADDRESS'\r\nSENDER_PASSWORD = 'GMAIL_APP_PASSWORD'\r\nSENDER_DOMAIN = 'smtp.gmail.com'\r\nSENDER_PORT = 465\r\n\r\n\r\ndef __send_email():\r\n    \"\"\"\r\n    \u30e1\u30fc\u30eb\u9001\u4fe1\r\n    \"\"\"\r\n    try:\r\n        email = 'RECIEVER@MAIL.ADDRESS'\r\n\r\n        # \u9001\u4fe1\u3059\u308b\u30e1\u30fc\u30eb\u306e\u5185\u5bb9\r\n        subject = '\u65e5\u672c\u8a9e\u306e\u30c6\u30b9\u30c8\u30e1\u30fc\u30eb'\r\n        body = \"\"\"\u65e5\u672c\u8a9e\u306e\u672c\u6587\u3067\u3059\u3002\r\n\u8907\u6570\u884c\u3067\u306e\u6587\u7ae0\u5165\u529b\u306e\u30c6\u30b9\u30c8\r\n\u6700\u5f8c\u306e\u884c\"\"\"\r\n\r\n        # \u9001\u4fe1\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u751f\u6210\r\n        message = MIMEText(body, 'plain', 'utf-8')\r\n        message['Subject'] = Header(subject, 'utf-8')\r\n        message['From'] = SENDER_EMAIL\r\n        message['To'] = email\r\n\r\n        # \u30e1\u30fc\u30eb\u9001\u4fe1\u5b9f\u884c\r\n        server = smtplib.SMTP_SSL(SENDER_DOMAIN, SENDER_PORT)\r\n        server.login(SENDER_EMAIL, SENDER_PASSWORD)\r\n        server.sendmail(SENDER_EMAIL, email, message.as_string())\r\n        server.close()\r\n\r\n    except Exception as e:\r\n        print(e)\r\n\r\n\r\nif __name__ == '__main__':\r\n    __send_email()\r\n<\/pre>\r\n\u69cb\u6210\u306f\u975e\u5e38\u306b\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u3002\r\n<ul>\r\n \t<li>4\u301c8\u884c\u76ee\u3001\u9001\u4fe1\u5143\u306e\u60c5\u5831<\/li>\r\n \t<li>19\u301c22\u884c\u76ee\u3001\u9001\u4fe1\u5185\u5bb9<\/li>\r\n \t<li>25\u301c28\u884c\u76ee\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u751f\u6210<\/li>\r\n \t<li>31\u301c34\u884c\u76ee\u3001\u30e1\u30fc\u30eb\u9001\u4fe1\u5b9f\u884c<\/li>\r\n<\/ul>\r\n\u7279\u7b46\u3059\u308b\u3068\u3059\u308c\u3070\u3001 6\u884c\u76ee\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u306b\u306f Gmail \u306e\u30a2\u30d7\u30ea\u30d1\u30b9\u30ef\u30fc\u30c9\uff08\u30ed\u30b0\u30a4\u30f3\u30d1\u30b9\u30ef\u30fc\u30c9\u3067\u306f\u306a\u3044\uff09\u3092\u7528\u3044\u308b\u3053\u3068\u3001 33\u884c\u76ee\u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u524d\u306b 32\u884c\u76ee\u306e\u30ed\u30b0\u30a4\u30f3\u51e6\u7406\u304c\u5fc5\u8981\u3067\u3042\u308b\u3053\u3068\u3067\u3059\u3002\r\n\u540c\u69d8\u306a\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067 Cloud Functions \u3067\u3082\u52d5\u4f5c\u3059\u308b\u3053\u3068\u3092\u78ba\u8a8d\u6e08\u307f\u3067\u3059\u3002\r\n<h1>\u307e\u3068\u3081<\/h1>\r\n\u4eca\u56de\u306f\u3001 Cloud Functions \u3067\u3082\u4f7f\u3048\u308b Python \u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u30d1\u30c3\u30b1\u30fc\u30b8 smtplib \u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002 Python \u306f\u6a19\u6e96\u3067\u3053\u306e\u3088\u3046\u306b\u7c21\u5358\u306b\u5229\u7528\u3067\u304d\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u5099\u3048\u3066\u3044\u308b\u306e\u304c\u5b09\u3057\u3044\u3067\u3059\u306d\u3002\u696d\u52d9\u7cfb\u30b7\u30b9\u30c6\u30e0\u3092\u958b\u767a\u3057\u3066\u3044\u308b\u3068\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u3053\u3068\u306f\u3088\u304f\u3042\u308b\u306e\u3067\u3001\u5927\u5909\u52a9\u304b\u308a\u307e\u3059\u3002\u305c\u3072\u7686\u3055\u3093\u3082\u3054\u5229\u7528\u304f\u3060\u3055\u3044\u3002","protected":false},"excerpt":{"rendered":"<p>Cloud Functions &#8211; Python Python \u306f\u6a19\u6e96\u3067\u591a\u7a2e\u591a\u69d8\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u3057\u304b\u3057 Cloud Functions \u3067\u306f\u5229\u7528\u3067\u304d\u306a\u3044\u3082\u306e\u3084\u3001\u6a5f\u80fd\u304c\u5236\u9650\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u304c\u3042\u308a\u3001\u3057\u304b\u3082\u30d0\u30fc\u30b8\u30e7\u30f3\u306b&#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4,51],"tags":[7,18,25,215],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/gb-j.com\/wp-json\/wp\/v2\/posts\/2495"}],"collection":[{"href":"https:\/\/gb-j.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gb-j.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gb-j.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gb-j.com\/wp-json\/wp\/v2\/comments?post=2495"}],"version-history":[{"count":4,"href":"https:\/\/gb-j.com\/wp-json\/wp\/v2\/posts\/2495\/revisions"}],"predecessor-version":[{"id":2501,"href":"https:\/\/gb-j.com\/wp-json\/wp\/v2\/posts\/2495\/revisions\/2501"}],"wp:attachment":[{"href":"https:\/\/gb-j.com\/wp-json\/wp\/v2\/media?parent=2495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gb-j.com\/wp-json\/wp\/v2\/categories?post=2495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gb-j.com\/wp-json\/wp\/v2\/tags?post=2495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}