{"id":20619725,"url":"https://github.com/twtrubiks/flask-mail-example","last_synced_at":"2025-04-15T11:55:16.180Z","repository":{"id":84518952,"uuid":"77283468","full_name":"twtrubiks/Flask-Mail-example","owner":"twtrubiks","description":"Flask-Mail - 使用 Python Flask 完成寄信功能","archived":false,"fork":false,"pushed_at":"2022-05-03T01:55:51.000Z","size":648,"stargazers_count":12,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T11:55:11.408Z","etag":null,"topics":["demo-mail","flask-mail","gmail","python-flask","smtp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twtrubiks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-24T13:08:23.000Z","updated_at":"2024-02-26T08:05:57.000Z","dependencies_parsed_at":"2023-03-02T04:30:27.162Z","dependency_job_id":null,"html_url":"https://github.com/twtrubiks/Flask-Mail-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2FFlask-Mail-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2FFlask-Mail-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2FFlask-Mail-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2FFlask-Mail-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twtrubiks","download_url":"https://codeload.github.com/twtrubiks/Flask-Mail-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249067775,"owners_count":21207395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["demo-mail","flask-mail","gmail","python-flask","smtp"],"created_at":"2024-11-16T12:12:22.310Z","updated_at":"2025-04-15T11:55:16.174Z","avatar_url":"https://github.com/twtrubiks.png","language":"Python","readme":"# Flask-Mail-example\nFlask-Mail - 使用 Python Flask 完成寄信功能\n\n* [線上Demo mail 純文件](http://pythontt-twtrubikscode.rhcloud.com/mail_page)\n* [線上Demo mail 圖片附件](http://pythontt-twtrubikscode.rhcloud.com/mail_page_img)\n* [Youtube Demo](https://youtu.be/qqOgDPSD3jc)\n\n常看到別人的網站有寄信功能，今天教你使用 Python [Flask](http://flask.pocoo.org/) 快速建立一個。\n\n使用 Python [Flask](http://flask.pocoo.org/) 搭配 [Flask-Mail](http://pythonhosted.org/Flask-Mail/)  實現寄信功能。\n\n本篇使用 Gmail 當作範例，其他的信箱應該大同小異，請自行研究。\n\n## 特色\n* 搭配 [Flask-Mail](http://pythonhosted.org/Flask-Mail/) 實現寄信功能。\n\n\n## 安裝套件 Flask-Mail\n請先確定電腦有安裝 [Python](https://www.python.org/)\n\n\n### Flask-Mail\n```\npip install Flask-Mail\n```\n\n記得將下方程式碼修改為自己的 Gmail 帳號和密碼\n```\napp.config.update(\n    DEBUG=False,\n    # EMAIL SETTINGS\n    MAIL_SERVER='smtp.gmail.com',\n    MAIL_PORT=465,\n    MAIL_USE_SSL=True,\n    MAIL_DEFAULT_SENDER=('admin', 'xxxxxx@gmail.com'),\n    MAIL_MAX_EMAILS=10,\n    MAIL_USERNAME='xxxxxxx@gmail.com',\n    MAIL_PASSWORD='xxxxxxxxx'\n)\n\nmail = Mail(app)\n```\n\n更多 Flask-Mail ，可參考  [Flask-Mail](http://pythonhosted.org/Flask-Mail/)\n\n\n\n## 使用 Gmail 寄信 - 前置作業\n\n### 第一步\n\n可以參考官網的說明  [使用其他電子郵件程式讀取 Gmail 郵件 (透過 IMAP 協定)](https://support.google.com/mail/answer/7126229?hl=zh-Hant)\n\n請先到自己的gmail，點右上角的齒輪，然後選 \u003cb\u003e設定\u003c/b\u003e，\n\n然後找到 \u003cb\u003e轉寄和POP/IMAP\u003c/b\u003e，選擇 \u003cb\u003e啟用IMAP\u003c/b\u003e，\n\n記得按\u003cb\u003e儲存變更\u003c/b\u003e。 這樣就完成第一步了。\n\n![alt tag](http://i.imgur.com/lutH7Ox.jpg)\n\n![alt tag](http://i.imgur.com/zu15YSB.jpg)\n\n### 第二步\n\n接著到 [Security Here](https://www.google.com/settings/security/lesssecureapps) 去開啟權限 (2022/5/30 後關閉)\n\n![alt tag](http://i.imgur.com/nMWcYDh.jpg)\n\n新的方法,\n\n到帳號的安全性, 一定要開啟兩步驟驗證,\n\n![alt tag](https://i.imgur.com/IMSPInG.png)\n\n接著設定應用程式密碼, 可以選 其他(自訂名稱)\n\n![alt tag](https://i.imgur.com/ds2Ia36.png)\n\n接著會跳出一組密碼\n\n![alt tag](https://i.imgur.com/11qtT9M.png)\n\n使用你的信箱帳號和這組應用程式密碼即可\n\n![alt tag](https://i.imgur.com/tHavtEa.png)\n\n## 執行畫面\n首頁\n\n![alt tag](http://i.imgur.com/QV7PSUF.jpg)\n\n送出信件\n\n![alt tag](http://i.imgur.com/nx3VKxR.jpg)\n\n收到的信件內容\n\n![alt tag](http://i.imgur.com/kM0uZMv.jpg)\n\n\nP.S \u003cbr\u003e\n\n\u003cb\u003e可能遇到的問題一 :\u003c/b\u003e\n\n有時候你會遇到 \u003cb\u003esmtplib.SMTPAuthenticationError\u003c/b\u003e 的錯誤訊息，\n\n通常是你在 \u003cb\u003e使用 Gmail 寄信 - 前置作業\u003c/b\u003e 的步驟二權限忘記開了。\n\n\u003cb\u003e可能遇到的問題二 :\u003c/b\u003e\n\n你在本機 ( localhost )可以正常運作，但當你部署上去你自己的環境的時候，\n\n卻又出現 \u003cb\u003esmtplib.SMTPAuthenticationError\u003c/b\u003e 的錯誤訊息，\n\n這時候你可以試著去改你的 Gmail 密碼，改成密碼是高強度並且第一個英文字母是大寫的!!\n\n## 執行環境\n* Python 3.4.3\n\n## Reference\n* [Flask-Mail](http://pythonhosted.org/Flask-Mail/)\n\n## License\nMIT license\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwtrubiks%2Fflask-mail-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwtrubiks%2Fflask-mail-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwtrubiks%2Fflask-mail-example/lists"}