{"id":730,"date":"2020-05-14T15:24:28","date_gmt":"2020-05-14T07:24:28","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=730"},"modified":"2020-05-14T15:28:49","modified_gmt":"2020-05-14T07:28:49","slug":"fastapi-mailbox-alarm-interface","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/","title":{"rendered":"FastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3"},"content":{"rendered":"\n
# pip3.7  install fastapi uvicorn \u5b89\u88c5 \n# uvicorn sendmail:app --reload --port 8888 --host 0.0.0.0 \u542f\u52a8<\/pre>\n\n\n\n
#vim  sendmail.py\n\n# -*- coding: UTF-8 -*-\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.header import Header\nfrom fastapi import FastAPI\nfrom pydantic import BaseModel\n\nmail_host = \"*******\" # \u8bbe\u7f6e\u670d\u52a1\u5668\nmail_user = \"********\" # \u7528\u6237\u540d\nmail_pass = \"********\" # \u53e3\u4ee4\n\nclass Item(BaseModel):\nReceives: list\nContent: str\ncc: list = None\n\napp = FastAPI()\n@app.post(\"\/sendmail\/\")\ndef send_mail(item: Item):\nmsg = MIMEText(item.Content)\nmsg['Subject'] = Header(\"\u533a\u5757\u94fe\u7cfb\u7edfv1.0\u4e0a\u7ebf\u901a\u77e5\",\"utf-8\")\nmsg['From'] = (\"%s<admin@*****.com>\") % (Header(\"\u96c6\u56e2\u533a\u5757\u94fe\u9879\u76ee\u90e8\",\"utf-8\"),)\nmsg['To'] = \",\".join(item.Receives)\ntry:\nserver = smtplib.SMTP()\nserver.connect(mail_host)\nserver.login(mail_user, mail_pass)s\nserver.sendmail(msg['From'], item.Receives, msg.as_string())\nserver.close()\nreturn True\nexcept Exception as e:\nprint(str(e))\nreturn str(e)\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

# pip3.7 install fastapi uvicorn \u5b89\u88c5 # uvicorn sendmail:<\/p>\n","protected":false},"author":1,"featured_media":735,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,13],"tags":[],"yoast_head":"\nFastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3 - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"FastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3 - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\" \/>\n<meta property=\"og:description\" content=\"# pip3.7 install fastapi uvicorn \u5b89\u88c5 # uvicorn sendmail:\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-14T07:24:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-14T07:28:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2020\/05\/wechat-picture-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1265\" \/>\n\t<meta property=\"og:image:height\" content=\"903\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"\u7ba1\u7406\u5458\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/\"},\"author\":{\"name\":\"\u7ba1\u7406\u5458\",\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\"},\"headline\":\"FastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3\",\"datePublished\":\"2020-05-14T07:24:28+00:00\",\"dateModified\":\"2020-05-14T07:28:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/\"},\"wordCount\":1,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\"},\"articleSection\":[\"Linux\",\"Python\"],\"inLanguage\":\"zh-CN\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/\",\"url\":\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/\",\"name\":\"FastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3 - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\",\"isPartOf\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#website\"},\"datePublished\":\"2020-05-14T07:24:28+00:00\",\"dateModified\":\"2020-05-14T07:28:49+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/#breadcrumb\"},\"inLanguage\":\"zh-CN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.linuxdevops.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\",\"item\":\"https:\/\/www.linuxdevops.cn\/linux\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"FastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.linuxdevops.cn\/#website\",\"url\":\"https:\/\/www.linuxdevops.cn\/\",\"name\":\"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\",\"description\":\"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\u7b14\u8bb0\",\"publisher\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\"},\"alternateName\":\"linuxdevops\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.linuxdevops.cn\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-CN\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\",\"name\":\"\u7ba1\u7406\u5458\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-CN\",\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg\",\"contentUrl\":\"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg\",\"width\":512,\"height\":512,\"caption\":\"\u7ba1\u7406\u5458\"},\"logo\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/\"},\"description\":\"\u7ba1\u7406\u5458\",\"url\":\"https:\/\/www.linuxdevops.cn\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"FastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3 - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/","og_locale":"zh_CN","og_type":"article","og_title":"FastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3 - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","og_description":"# pip3.7 install fastapi uvicorn \u5b89\u88c5 # uvicorn sendmail:","og_url":"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/","og_site_name":"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","article_published_time":"2020-05-14T07:24:28+00:00","article_modified_time":"2020-05-14T07:28:49+00:00","og_image":[{"width":1265,"height":903,"url":"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2020\/05\/wechat-picture-1.png","type":"image\/png"}],"author":"\u7ba1\u7406\u5458","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/#article","isPartOf":{"@id":"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/"},"author":{"name":"\u7ba1\u7406\u5458","@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1"},"headline":"FastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3","datePublished":"2020-05-14T07:24:28+00:00","dateModified":"2020-05-14T07:28:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/"},"wordCount":1,"commentCount":0,"publisher":{"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1"},"articleSection":["Linux","Python"],"inLanguage":"zh-CN","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/","url":"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/","name":"FastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3 - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","isPartOf":{"@id":"https:\/\/www.linuxdevops.cn\/#website"},"datePublished":"2020-05-14T07:24:28+00:00","dateModified":"2020-05-14T07:28:49+00:00","breadcrumb":{"@id":"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/#breadcrumb"},"inLanguage":"zh-CN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.linuxdevops.cn\/2020\/05\/fastapi-mailbox-alarm-interface\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.linuxdevops.cn\/"},{"@type":"ListItem","position":2,"name":"Linux","item":"https:\/\/www.linuxdevops.cn\/linux\/"},{"@type":"ListItem","position":3,"name":"FastApi \u90ae\u7bb1\u544a\u8b66\u63a5\u53e3"}]},{"@type":"WebSite","@id":"https:\/\/www.linuxdevops.cn\/#website","url":"https:\/\/www.linuxdevops.cn\/","name":"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","description":"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\u7b14\u8bb0","publisher":{"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1"},"alternateName":"linuxdevops","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.linuxdevops.cn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-CN"},{"@type":["Person","Organization"],"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1","name":"\u7ba1\u7406\u5458","image":{"@type":"ImageObject","inLanguage":"zh-CN","@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/","url":"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg","contentUrl":"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg","width":512,"height":512,"caption":"\u7ba1\u7406\u5458"},"logo":{"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/"},"description":"\u7ba1\u7406\u5458","url":"https:\/\/www.linuxdevops.cn\/author\/root\/"}]}},"_links":{"self":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts\/730"}],"collection":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/comments?post=730"}],"version-history":[{"count":3,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts\/730\/revisions"}],"predecessor-version":[{"id":734,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts\/730\/revisions\/734"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/media\/735"}],"wp:attachment":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/media?parent=730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/categories?post=730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/tags?post=730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}