{"id":12839,"date":"2020-07-29T11:41:02","date_gmt":"2020-07-29T02:41:02","guid":{"rendered":"https:\/\/sendgrid.kke.co.jp\/blog\/?p=12839"},"modified":"2026-04-13T15:07:43","modified_gmt":"2026-04-13T06:07:43","slug":"twilio-sendgrid%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6python-flask%e3%81%a7%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%92%e9%80%81%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/sendgrid.kke.co.jp\/blog\/?p=12839","title":{"rendered":"Twilio SendGrid\u3092\u4f7f\u3063\u3066Python Flask\u3067\u30e1\u30fc\u30eb\u3092\u9001\u308b\u65b9\u6cd5"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/cDU7zWGe29zwZrksND3EeNeAlXtudWwTJHxugIezfRfZYS.width-808.png\" alt=\"Twilio SendGrid\u3092\u4f7f\u3063\u3066Python Flask\u3067\u30e1\u30fc\u30eb\u3092\u9001\u308b\u65b9\u6cd5\" width=\"100%\" class=\"aligncenter size-full wp-image-12840\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/cDU7zWGe29zwZrksND3EeNeAlXtudWwTJHxugIezfRfZYS.width-808.png 808w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/cDU7zWGe29zwZrksND3EeNeAlXtudWwTJHxugIezfRfZYS.width-808-300x150.png 300w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/cDU7zWGe29zwZrksND3EeNeAlXtudWwTJHxugIezfRfZYS.width-808-768x384.png 768w\" sizes=\"(max-width: 808px) 100vw, 808px\" \/><\/p>\n<blockquote>\n<p>\u3053\u306e\u8a18\u4e8b\u306f <a href=\"https:\/\/www.twilio.com\/blog\/using-twilio-sendgrid-to-send-emails-from-python-flask-applications\" target=\"_blank\">Using Twilio SendGrid To Send Emails from Python Flask Applications<\/a> \u306e\u6284\u8a33\u3067\u3059\u3002<\/p>\n<\/blockquote>\n<p>Web\u30a2\u30d7\u30ea\u306b\u30e1\u30fc\u30eb\u9001\u4fe1\u6a5f\u80fd\u3092\u3069\u3046\u7d44\u307f\u8fbc\u3080\u304b\u306f\u5e38\u306b\u5384\u4ecb\u306a\u554f\u984c\u3067\u3059\u3002\u81ea\u5206\u81ea\u8eab\u3067\u30e1\u30fc\u30eb\u30b5\u30fc\u30d0\u3092\u7528\u610f\u3057\u7ba1\u7406\u3059\u308b\u306e\u304b\u3001\u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u306e\u30e1\u30fc\u30eb\u914d\u4fe1\u30b5\u30fc\u30d3\u30b9\u3092\u4f7f\u3046\u306e\u304b\u2026\u2026\u3002\u30e1\u30fc\u30eb\u914d\u4fe1\u91cf\u3084\u4e88\u7b97\u3001Web\u30a2\u30d7\u30ea\u306b\u3069\u3093\u306a\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u3092\u7528\u3044\u308b\u304b\u306a\u3069\u69d8\u3005\u306a\u8981\u56e0\u306b\u5de6\u53f3\u3055\u308c\u307e\u3059\u304c\u3001\u30e1\u30fc\u30eb\u914d\u4fe1\u30b5\u30fc\u30d3\u30b9\u306e\u30b7\u30f3\u30d7\u30eb\u3055\u304c\u597d\u307e\u308c\u308b\u5834\u5408\u304c\u591a\u3044\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u3001Python\u306eWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3042\u308b<a href=\"https:\/\/palletsprojects.com\/p\/flask\/\" rel=\"noopener\" target=\"_blank\">Flask<\/a>\u3068\u3001\u305d\u306e\u62e1\u5f35\u6a5f\u80fd<a href=\"https:\/\/pypi.org\/project\/Flask-Mail\/\" rel=\"noopener\" target=\"_blank\">Flask-Mail<\/a>\u3092\u7528\u3044\u3066\u3001<a href=\"https:\/\/sendgrid.kke.co.jp\/\" rel=\"noopener\" target=\"_blank\">Twilio SendGrid<\/a>\u3067\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h3>\u5fc5\u8981\u306a\u30c4\u30fc\u30eb<\/h3>\n<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306b\u306f\u4ee5\u4e0b\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<ul>\n<li>Python 3.6\u4ee5\u4e0a: \u304a\u4f7f\u3044\u306eOS\u306b\u3042\u3089\u304b\u3058\u3081\u30a4\u30f3\u30bf\u30d7\u30ea\u30bf\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u3001<a href=\"https:\/\/www.python.org\/\" rel=\"noopener\" target=\"_blank\">python.org<\/a>\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3002<\/li>\n<li>SendGrid\u30a2\u30ab\u30a6\u30f3\u30c8\uff08\u3054\u767b\u9332\u306f<a href=\"https:\/\/sendgrid.kke.co.jp\/app?p=signup.index&#038;utm_source=sg&#038;utm_medium=web&#038;utm_campaign=blog\" target=\"_blank\" rel=\"noopener\">\u3053\u3061\u3089<\/a>\u304b\u3089\uff09<\/li>\n<\/ul>\n<h3>SendGrid\u306e\u8a2d\u5b9a\u3092\u884c\u3046<\/h3>\n<p>SendGrid\u304b\u3089\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b\u524d\u306b\u3001\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u8a8d\u8a3c\u60c5\u5831\u3068\u3057\u3066\u7528\u3044\u308bAPI\u30ad\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u30a2\u30ab\u30a6\u30f3\u30c8\u306b<a href=\"https:\/\/sendgrid.kke.co.jp\/app?p=login.index\" rel=\"noopener\" target=\"_blank\">\u30ed\u30b0\u30a4\u30f3<\/a>\u3057\u305f\u3089\u3001\u5de6\u5074\u306e\u30e1\u30cb\u30e5\u30fc\u306e\u201cSettings\u201d\u304b\u3089\u201c<a href=\"https:\/\/app.sendgrid.com\/settings\/api_keys\" rel=\"noopener\" target=\"_blank\">API Keys<\/a>\u201d\u3092\u9078\u3073\u3001\u201cCreate API Key\u201d\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/YrA9d5CZ4Z2KGTk6SQS8n0pCgsRJmEx8FEDgGD1mf7NETl.width-500.png\" alt=\"Create API Key\" width=\"80%\" class=\"aligncenter size-full wp-image-12841\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/YrA9d5CZ4Z2KGTk6SQS8n0pCgsRJmEx8FEDgGD1mf7NETl.width-500.png 500w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/YrA9d5CZ4Z2KGTk6SQS8n0pCgsRJmEx8FEDgGD1mf7NETl.width-500-300x211.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/p>\n<p>API\u30ad\u30fc\u306b\u306f\u308f\u304b\u308a\u3084\u3059\u3044\u540d\u524d\u3092\u3064\u3051\u307e\u3057\u3087\u3046\u3002\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306fFlask-Mail\u3068\u3044\u3046\u540d\u524d\u306b\u3057\u307e\u3059\u3002Permissions\u306b\u201cFull Access\u201d\u3092\u9078\u3076\u3053\u3068\u3067\u3001\u30e1\u30fc\u30eb\u9001\u4fe1\u306b\u5fc5\u8981\u306a\u5168\u3066\u306e\u6a5f\u80fd\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u7279\u5b9a\u306e\u6a29\u9650\u3060\u3051\u6301\u3064API\u30ad\u30fc\u3092\u4f5c\u6210\u3057\u305f\u3044\u5834\u5408\u306b\u306f\u3001\u201cRestricted Access\u201d\u3092\u9078\u3093\u3067\u5fc5\u8981\u306a\u6a29\u9650\u3092\u4e0e\u3048\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u201cCreate &#038; View\u201d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308c\u3070\u3001API\u30ad\u30fc\u306e\u6587\u5b57\u5217\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u3053\u306e\u6587\u5b57\u5217\u306f\u4e00\u5ea6\u3057\u304b\u8868\u793a\u3067\u304d\u306a\u3044\u306e\u3067\u3001\u3042\u3068\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u306b\u30b3\u30d4\u30fc\u3057\u3066\u30bb\u30ad\u30e5\u30a2\u306a\u5834\u6240\u306b\u30da\u30fc\u30b9\u30c8\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002\u30ad\u30fc\u3092\u4fdd\u5b58\u3057\u305f\u3089\u3001\u201cDone\u201d\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u307e\u3059\u3002<\/p>\n<h3>Python\u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b<\/h3>\n<p>\u305d\u308c\u3067\u306f\u3001Flask\u30a2\u30d7\u30ea\u3067\u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u65b9\u6cd5\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002twilio-sendgrid-tests\u306e\u3088\u3046\u306a\u540d\u524d\u3067\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3001\u305d\u306e\u4e2d\u306b\u65b0\u3057\u304fPython\u306e\u4eee\u60f3\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>Mac\u307e\u305f\u306fUnix\u30e6\u30fc\u30b6\u306e\u5834\u5408\u3001\u30b3\u30de\u30f3\u30c9\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$ mkdir twilio-sendgrid-tests\n$ cd twilio-sendgrid-tests\n$ python3 -m venv venv\n$ source venv\/bin\/activate\n(venv) $ _\n<\/pre>\n<p>Windows\u30e6\u30fc\u30b6\u306e\u5834\u5408\u3001\u30b3\u30de\u30f3\u30c9\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$ mkdir twilio-sendgrid-tests\n$ cd twilio-sendgrid-tests\n$ python -m venv venv\n$ venv\\Scripts\\activate\n(venv) $ _\n<\/pre>\n<p>\u6b21\u306b\u3001\u4eee\u60f3\u74b0\u5883\u3078Flask\u3068Flask-Mail\u3001python-dotenv\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n(venv) $ pip install flask flask-mail python-dotenv\n<\/pre>\n<h3>Flask\u30a2\u30d7\u30ea\u3092\u4f5c\u308b<\/h3>\n<p>app.py\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3001\u521d\u3081\u3066\u306eFlask\u30fbFlask-Mail\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u88c5\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport os\nfrom flask import Flask, render_template, request, redirect, url_for, flash\nfrom flask_mail import Mail, Message\n\napp = Flask(__name__)\napp.config&#x5B;&#039;SECRET_KEY&#039;] = &#039;top-secret!&#039;\napp.config&#x5B;&#039;MAIL_SERVER&#039;] = &#039;smtp.sendgrid.net&#039;\napp.config&#x5B;&#039;MAIL_PORT&#039;] = 587\napp.config&#x5B;&#039;MAIL_USE_TLS&#039;] = True\napp.config&#x5B;&#039;MAIL_USERNAME&#039;] = &#039;apikey&#039;\napp.config&#x5B;&#039;MAIL_PASSWORD&#039;] = os.environ.get(&#039;SENDGRID_API_KEY&#039;)\napp.config&#x5B;&#039;MAIL_DEFAULT_SENDER&#039;] = os.environ.get(&#039;MAIL_DEFAULT_SENDER&#039;)\nmail = Mail(app)\n<\/pre>\n<p>\u3053\u3061\u3089\u306f\u3001SendGrid\u306eSMTP\u3092\u7528\u3044\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b\u305f\u3081\u306e\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u30e1\u30fc\u30eb\u30b5\u30fc\u30d0\u3068\u3057\u3066smtp.sendgrid.net\u3092\u6307\u5b9a<\/li>\n<li>\u30dd\u30fc\u30c8\u756a\u53f7\u3068\u3057\u3066587\u3092\u6307\u5b9a\uff0825\u756a\u3067\u3082\u53ef\uff09<\/li>\n<li>TLS\u901a\u4fe1\u3092\u6709\u52b9\u5316<\/li>\n<li>\u8a8d\u8a3c\u60c5\u5831\u3068\u3057\u3066\u3001\u30e6\u30fc\u30b6\u540d\u306bapikey\uff08\u5168\u3066\u306eSendGrid\u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u5171\u901a\uff09\u3092\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u306b\u5148\u307b\u3069\u4f5c\u6210\u3057\u305fAPI\u30ad\u30fc\u3092\u6307\u5b9a\n<\/ul>\n<p>\u4e0a\u8a18\u306e\u9805\u76ee\u3092Flask-Mail\u306e\u8a2d\u5b9a\u9805\u76ee\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002\u8a8d\u8a3c\u60c5\u5831\u3092\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306b\u9855\u306b\u66f8\u304f\u306e\u306f\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u4e0a\u597d\u307e\u3057\u304f\u306a\u3044\u305f\u3081\u3001OS\u4e0a\u306bAPI\u30ad\u30fc\u3092<span style=\"background-color:#d3d3d3\">SENDGRID_API_KEY<\/span>\u3068\u3044\u3046\u74b0\u5883\u5909\u6570\u3068\u3057\u3066\u4fdd\u5b58\u3057\u3001\u305d\u308c\u3092\u547c\u3073\u51fa\u3059\u5f62\u306b\u3057\u307e\u3059\u3002\u307e\u305f\u3001\u5dee\u51fa\u4eba\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3082\u74b0\u5883\u5909\u6570\u3067\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306f\u53d7\u4fe1\u30e1\u30fc\u30eb\u306e\u300cFrom\u300d\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>.env\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u30012\u3064\u306e\u5909\u6570\u3092\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\nSENDGRID_API_KEY=&quot;&lt;your-sendgrid-api-key&gt;&quot;\nMAIL_DEFAULT_SENDER=&quot;&lt;your-sender-email-address&gt;&quot;\n<\/pre>\n<p>python-dotenv\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308c\u3070\u3001\u3053\u308c\u3089\u306e\u5909\u6570\u304c\u81ea\u52d5\u7684\u306b\u8aad\u307f\u8fbc\u307e\u308c\u308b\u306e\u3067\u3001Flask\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30e1\u30fc\u30eb\u3092\u9001\u308b<\/h3>\n<p>\u305d\u308c\u3067\u306f\u3001Python\u30b7\u30a7\u30eb\u304b\u3089\u81ea\u5206\u81ea\u8eab\u306b\u5411\u3051\u3066\u30c6\u30b9\u30c8\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n(venv) $ flask shell\n<\/pre>\n<p><span style=\"background-color:#d3d3d3\">flask shell<\/span>\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001app.py\u3067\u5b9f\u88c5\u3057\u305fFlask\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8aad\u307f\u8fbc\u307f\u3001<span style=\"background-color:#d3d3d3\">mail<\/span>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3068Flask-Mail\u306e<span style=\"background-color:#d3d3d3\">Message<\/span>\u30af\u30e9\u30b9\u3092import\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nfrom app import mail\nfrom flask_mail import Message\n<\/pre>\n<p>\u6b21\u306b\u3001<span style=\"background-color:#d3d3d3\">Message<\/span>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nmsg = Message(&#039;Twilio SendGrid Test Email&#039;, recipients=&#x5B;&#039;recipient@example.com&#039;])\nmsg.body = &#039;This is a test email!&#039;\nmsg.html = &#039;&lt;p&gt;This is a test email!&lt;\/p&gt;&#039;\n<\/pre>\n<p>\u6700\u5f8c\u306b\u3001\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\nmail.send(msg)\n<\/pre>\n<p>\u3046\u307e\u304f\u3044\u3051\u3070\u3001\u6570\u79d2\u306e\u3046\u3061\u306b\u53d7\u4fe1\u30dc\u30c3\u30af\u30b9\u3078\u30e1\u30fc\u30eb\u304c\u5c4a\u304f\u306f\u305a\u3067\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/9mJf33Xnuf11J5mwS739CdsXTS3ER9ArjNRdxDh8_frjyk.width-500.png\" alt=\"\u53d7\u4fe1\u30dc\u30c3\u30af\u30b9\" width=\"80%\" class=\"aligncenter size-full wp-image-12842\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/9mJf33Xnuf11J5mwS739CdsXTS3ER9ArjNRdxDh8_frjyk.width-500.png 500w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/9mJf33Xnuf11J5mwS739CdsXTS3ER9ArjNRdxDh8_frjyk.width-500-300x155.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/p>\n<p>\u5b9f\u969b\u306bFlask\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u7d44\u307f\u8fbc\u3093\u3067\u307f\u305f\u3044\u5834\u5408\u306f\u3001app.py\u306e\u672b\u5c3e\u306b\u4ee5\u4e0b\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\n@app.route(&#039;\/&#039;, methods=&#x5B;&#039;GET&#039;, &#039;POST&#039;])\ndef index():\n   if request.method == &#039;POST&#039;:\n       recipient = request.form&#x5B;&#039;recipient&#039;]\n       msg = Message(&#039;Twilio SendGrid Test Email&#039;, recipients=&#x5B;recipient])\n       msg.body = (&#039;Congratulations! You have sent a test email with &#039;\n                   &#039;Twilio SendGrid!&#039;)\n       msg.html = (&#039;&lt;h1&gt;Twilio SendGrid Test Email&lt;\/h1&gt;&#039;\n                   &#039;&lt;p&gt;Congratulations! You have sent a test email with &#039;\n                   &#039;&lt;b&gt;Twilio SendGrid&lt;\/b&gt;!&lt;\/p&gt;&#039;)\n       mail.send(msg)\n       flash(f&#039;A test message was sent to {recipient}.&#039;)\n       return redirect(url_for(&#039;index&#039;))\n   return render_template(&#039;index.html&#039;)\n<\/pre>\n<p>\u6b21\u306b\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30ebindex.html\u304c\u5fc5\u8981\u3067\u3059\u3002\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u7528\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n(venv) $ mkdir templates\n<\/pre>\n<p>templates\/index.html\u306b\u4ee5\u4e0b\u306eHTML\u30bd\u30fc\u30b9\u3092\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;!doctype html&gt;\n&lt;html&gt;\n   &lt;head&gt;\n       &lt;title&gt;Twilio SendGrid Example&lt;\/title&gt;\n   &lt;\/head&gt;\n   &lt;body&gt;\n       &lt;h1&gt;Twilio SendGrid Example&lt;\/h1&gt;\n       {% with messages = get_flashed_messages() %}\n       {% for message in messages %}\n       &lt;p&gt;{{ message }}&lt;\/p&gt;\n       {% endfor %}\n       {% endwith %}\n       &lt;form action=&quot;&quot; method=&quot;post&quot;&gt;\n           &lt;p&gt;Your email: &lt;input type=&quot;text&quot; name=&quot;recipient&quot;&gt;&lt;\/p&gt;\n           &lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Send a Test Email&quot;&gt;&lt;\/p&gt;\n       &lt;\/form&gt;\n   &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8d77\u52d5\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n(venv) $ flask run\n<\/pre>\n<p>\u30d6\u30e9\u30a6\u30b6\u3067 http:\/\/localhost:5000 \u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u305f\u3089\u6210\u529f\u3067\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/L2n4Nj1msKxxcWrA7E573M0uqIRQY9gqIK_feHpqM3dxRp.width-500.png\" alt=\"Twilio SendGrid Example\" width=\"80%\" class=\"noshadow aligncenter size-full wp-image-12843\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/L2n4Nj1msKxxcWrA7E573M0uqIRQY9gqIK_feHpqM3dxRp.width-500.png 500w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/07\/L2n4Nj1msKxxcWrA7E573M0uqIRQY9gqIK_feHpqM3dxRp.width-500-300x238.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/p>\n<p>\u5b9b\u5148\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u5165\u529b\u3057\u3066\u300cSend a Test Email\u300d\u30dc\u30bf\u30f3\u3092\u9078\u629e\u3059\u308b\u3068\u3001\u30e1\u30fc\u30eb\u304c\u9001\u4fe1\u3055\u308c\u307e\u3059\u3002\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f<a href=\"https:\/\/github.com\/miguelgrinberg\/sendgrid-flask-mail\" rel=\"noopener\" target=\"_blank\">GitHub<\/a>\u304b\u3089\u3082\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30e1\u30fc\u30eb\u304c\u5c4a\u304b\u306a\u304b\u3063\u305f\u3089<\/h3>\n<p>\u554f\u984c\u306a\u304f\u30e1\u30fc\u30eb\u9001\u4fe1\u304c\u6210\u529f\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u9858\u3044\u307e\u3059\u304c\u3001\u5c4a\u304b\u306a\u3044\u30b1\u30fc\u30b9\u3082\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002SendGrid\u306f\u30e1\u30fc\u30eb\u9001\u4fe1\u3092\u975e\u540c\u671f\u7684\u306b\u884c\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u307b\u3068\u3093\u3069\u306e\u554f\u984c\u306f\u9001\u4fe1\u6307\u793a\u3092\u5b8c\u4e86\u3057\u305f\u5f8c\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u30e1\u30fc\u30eb\u9001\u4fe1\u8005\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u9001\u4fe1\u30a8\u30e9\u30fc\u306e\u767a\u751f\u304c\u308f\u304b\u3089\u306a\u3044\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002\u591a\u304f\u306e\u5834\u5408\u3001\u5c4a\u304b\u306a\u3044\u539f\u56e0\u306f\u5b9b\u5148\u5074\u30e1\u30fc\u30eb\u30b5\u30fc\u30d0\u306b\u3088\u308b\u53d7\u4fe1\u62d2\u5426\u3067\u3059\u3002<\/p>\n<p>\u9001\u4fe1\u3057\u305f\u30e1\u30fc\u30eb\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u306fSendGrid\u306e\u753b\u9762\u304b\u3089\u78ba\u8a8d\u3057\u307e\u3059\u3002<a href=\"https:\/\/app.sendgrid.com\/\" rel=\"noopener\" target=\"_blank\">\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9<\/a>\u304b\u3089<a href=\"https:\/\/app.sendgrid.com\/email_activity\" rel=\"noopener\" target=\"_blank\">Activity<\/a>\u3092\u9078\u629e\u3059\u308b\u3068\u3001\u767a\u751f\u3057\u305f\u30a4\u30d9\u30f3\u30c8\u306e\u4e00\u89a7\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002Activity\u3067\u306f\u3001\u9001\u4fe1\u3092\u8a66\u307f\u305f\u30e1\u30fc\u30eb\u306e\u30ea\u30b9\u30c8\u3068\u305d\u308c\u3089\u306e\u30e1\u30fc\u30eb\u304c\u5c4a\u3044\u305f\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u8a73\u3057\u3044\u30a4\u30d9\u30f3\u30c8\u306e\u898b\u65b9\u306f<a href=\"https:\/\/sendgrid.kke.co.jp\/docs\/Tutorials\/C_Manage_Events\/using_activity.html\" rel=\"noopener\" target=\"_blank\">\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u304a\u308f\u308a\u306b<\/h3>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001Twilio SendGrid\u3068Flask-Mail\u3092\u4f7f\u3046\u3068Flask\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304b\u3089\u7c21\u5358\u306b\u30e1\u30fc\u30eb\u9001\u4fe1\u3067\u304d\u307e\u3059\u3002\u305c\u3072\u304a\u8a66\u3057\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3082\u3063\u3068\u697d\u3057\u304f\u5b66\u3076\u306b\u306f\u3001<a href=\"https:\/\/www.twilio.com\/quest\" rel=\"noopener\" target=\"_blank\">Twilio Quest<\/a>\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066SendGrid\u306e\u30df\u30c3\u30b7\u30e7\u30f3\u306b\u30c1\u30e3\u30ec\u30f3\u30b8\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u8a18\u4e8b\u306f Using Twilio SendGrid To Send Emails from Python Flask Applications \u306e\u6284\u8a33\u3067\u3059\u3002 Web\u30a2\u30d7\u30ea\u306b\u30e1\u30fc\u30eb\u9001\u4fe1\u6a5f\u80fd\u3092\u3069\u3046\u7d44\u307f\u8fbc\u3080\u304b\u306f\u5e38\u306b\u5384\u4ecb\u306a\u554f <a class=\"read-more\" href=\"https:\/\/sendgrid.kke.co.jp\/blog\/?p=12839\">&#8230;\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":12840,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11,8],"tags":[],"class_list":["post-12839","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technical","category-product"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12839"}],"version-history":[{"count":10,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12839\/revisions"}],"predecessor-version":[{"id":20635,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12839\/revisions\/20635"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/media\/12840"}],"wp:attachment":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}