{"id":131,"date":"2023-12-05T08:44:39","date_gmt":"2023-12-05T08:44:39","guid":{"rendered":"https:\/\/mailmug.net\/blog\/?p=131"},"modified":"2026-01-01T06:15:00","modified_gmt":"2026-01-01T06:15:00","slug":"fastapi-mail","status":"publish","type":"post","link":"https:\/\/mailmug.net\/blog\/fastapi-mail\/","title":{"rendered":"Sending Emails with Python FastAPI: A Quick Guide"},"content":{"rendered":"\n<p>Learn how to send emails using Python <a href=\"https:\/\/fastapi.tiangolo.com\/\">FastAPI<\/a> with step-by-step instructions. This guide includes code examples for sending emails with SMTP, HTML email templates, attachments, to multiple recipients, and more.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>We are using the Python standard module <code>smtplib<\/code>. The <strong>smtplib<\/strong> is helping to connect the SMTP server and send emails.<\/p>\n\n\n\n<p>Navigate to the desired topic by clicking on the items in the table of contents below.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#install-packages\">Install the packages<\/a><\/li>\n\n\n\n<li><a href=\"#smtp-sandbox-account\">Create SandBox SMTP Email Account<\/a><\/li>\n\n\n\n<li><a href=\"#send-email\">FastAPI Send Simple Email By SMTP<\/a><\/li>\n\n\n\n<li><a href=\"#multiple-recipients\">FatAPI Email to Multiple Recipients<\/a><\/li>\n\n\n\n<li><a href=\"#bcc-cc\">How to Add Bcc, Cc in Python FastAPI Email?<\/a><\/li>\n\n\n\n<li><a href=\"#smtp-files\">How to Send Python FastAPI Emails With Attached Files?<\/a><\/li>\n\n\n\n<li><a href=\"#debug\">Change SMTPlib Debug Option<\/a><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Sending Emails with Python FastAPI\" width=\"640\" height=\"480\" src=\"https:\/\/www.youtube.com\/embed\/JhkFOw6qLLE?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<div style=\"height:58px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"install-packages\">Install Python Packages<\/h2>\n\n\n\n<p>First, we can create a test FastAPI route to send an email. Install the FastAPI and uvicorn modules.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\npip install fastapi \"uvicorn&#x5B;standard]\"\n<\/pre><\/div>\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"smtp-sandbox-account\">Create SandBox SMTP Email Account <\/h2>\n\n\n\n<p>MailMug.net provides a free SMTP account. You can easily test the mail function from your local or production server without sending it to a real email. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/mailmug.net\/register\"><img loading=\"lazy\" decoding=\"async\" width=\"631\" height=\"262\" src=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/credentials.png\" alt=\"SMPT Sandbox account for php flight\" class=\"wp-image-75\" style=\"width:840px;height:auto\" srcset=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/credentials.png 631w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/credentials-300x125.png 300w\" sizes=\"(max-width: 631px) 100vw, 631px\" \/><\/a><\/figure>\n\n\n\n<p>Create an account now (<a href=\"https:\/\/mailmug.net\/register\">MailMug.net<\/a>). Then start testing.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mailmug.net\/\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/sandbox-1024x576.png\" alt=\"SMTP Sandbox\" class=\"wp-image-267\" srcset=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/sandbox-1024x576.png 1024w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/sandbox-300x169.png 300w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/sandbox-768x432.png 768w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/sandbox.png 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"send-email\">FastAPI Send Simple Email By SMTP<\/h2>\n\n\n\n<p>Create a <strong>main.py<\/strong> file then add the following code. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom fastapi import FastAPI\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n \napp = FastAPI()\n \nport = 2525\nsmtp_server = &quot;smtp.mailmug.net&quot;\nlogin = &quot;username here&quot; # paste your login generated by mailmug\npassword = &quot;pass here&quot; # paste your password generated by mailmug\n \nsender_email = &quot;mailmug@example.com&quot;\nreceiver_email = &quot;new@example.com&quot;\nmessage = MIMEMultipart(&quot;alternative&quot;)\nmessage&#x5B;&quot;Subject&quot;] = &quot;Test subject&quot;\nmessage&#x5B;&quot;From&quot;] = sender_email\nmessage&#x5B;&quot;To&quot;] = receiver_email\n \n \n@app.get(&quot;\/send-email&quot;)\ndef send_email():\n \n     # write the HTML part\n    html = &quot;&quot;&quot;\\\n        &lt;html&gt;\n        &lt;body&gt;\n            &lt;p&gt;Hi,&lt;br&gt;\n            This is the test email&lt;\/p&gt;\n        &lt;\/body&gt;\n        &lt;\/html&gt;\n        &quot;&quot;&quot;\n    part = MIMEText(html, &quot;html&quot;)\n    message.attach(part)\n \n    server = smtplib.SMTP(smtp_server, port)\n    server.set_debuglevel(1)\n    server.esmtp_features&#x5B;&#039;auth&#039;] = &#039;LOGIN DIGEST-MD5 PLAIN&#039;\n    server.login(login, password)\n    server.sendmail(\n        sender_email, receiver_email, message.as_string()\n    )\n \n \n    return {&quot;msg&quot;:&quot;send mail&quot;}\n<\/pre><\/div>\n\n\n<p>Then execute the following command from the terminal to start the server. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nuvicorn main:app --reload\n<\/pre><\/div>\n\n\n<p>Finally, navigate <strong>http:\/\/127.0.0.1:8000<\/strong> from your browser. <\/p>\n\n\n\n<div style=\"height:61px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"multiple-recipients\">How to Send Email to Multiple Recipients From Python FastAPI?<\/h2>\n\n\n\n<p>We can send emails to multiple recipients by adding an email address list to <strong>receiver_email<\/strong> in <strong>SMTPlib<\/strong>. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nreceiver_email =  &#x5B;\"new@example.com\", \"new1@example.com\"]\n<\/pre><\/div>\n\n\n<p><strong>Complete Code<\/strong>:-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom fastapi import FastAPI\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\napp = FastAPI()\n\nport = 2525 \nsmtp_server = &quot;smtp.mailmug.net&quot;\nlogin = &quot;username here&quot; # paste your login generated by mailmug\npassword = &quot;pass&quot; # paste your password generated by mailmug\n\nsender_email = &quot;mailmug@example.com&quot;\nreceiver_email =  &#x5B;&quot;new@example.com&quot;, &quot;new1@example.com&quot;]\nmessage = MIMEMultipart(&quot;alternative&quot;)\nmessage&#x5B;&quot;Subject&quot;] = &quot;Test subject&quot;\nmessage&#x5B;&quot;From&quot;] = sender_email\n\nif isinstance(receiver_email, str):\n    message&#x5B;&quot;To&quot;] = receiver_email\nelse:\n    message&#x5B;&quot;To&quot;] = &quot;, &quot;.join(receiver_email)\n\n\n@app.get(&quot;\/send-email&quot;)\ndef send_email():\n\n     # write the HTML part\n    html = &quot;&quot;&quot;\\\n        &lt;html&gt;\n        &lt;body&gt;\n            &lt;p&gt;Hi,&lt;br&gt;\n            This is the test email&lt;\/p&gt;\n        &lt;\/body&gt;\n        &lt;\/html&gt;\n        &quot;&quot;&quot;\n    part = MIMEText(html, &quot;html&quot;)\n    message.attach(part)\n\n    server = smtplib.SMTP(smtp_server, port)\n    server.set_debuglevel(1)\n    server.esmtp_features&#x5B;&quot;auth&quot;] = &quot;LOGIN DIGEST-MD5 PLAIN&quot;\n    server.login(login, password)\n    server.sendmail(\n        sender_email, receiver_email, message.as_string()\n    )\n\n\n    return {&quot;msg&quot;:&quot;send mail&quot;} \n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/Multiple-Recipients-From-Python.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"313\" src=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/Multiple-Recipients-From-Python-1024x313.png\" alt=\"\" class=\"wp-image-151\" srcset=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/Multiple-Recipients-From-Python-1024x313.png 1024w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/Multiple-Recipients-From-Python-300x92.png 300w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/Multiple-Recipients-From-Python-768x235.png 768w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/Multiple-Recipients-From-Python.png 1084w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Multiple Recipients From Python FastAPI<\/figcaption><\/figure>\n\n\n\n<div style=\"height:69px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bcc-cc\">How to Add Bcc, Cc in Python FastAPI Email?<\/h2>\n\n\n\n<p>Pass &#8216;<strong>Cc<\/strong>&#8216; or &#8216;<strong>Bcc<\/strong>&#8216; to the <strong>MIMEMultipart<\/strong> message. It will automatically add to the email header part. <\/p>\n\n\n\n<p><strong>Example code:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nmessage&#x5B;\"Bcc\"] = \"bcc@example.com\"\nmessage&#x5B;\"Cc\"] = \"cc@example.com\"\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/python-email-bcc-cc.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"525\" src=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/python-email-bcc-cc-1024x525.png\" alt=\"Bcc, Cc in Python FastAPI Email\" class=\"wp-image-164\" style=\"width:840px;height:auto\" srcset=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/python-email-bcc-cc-1024x525.png 1024w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/python-email-bcc-cc-300x154.png 300w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/python-email-bcc-cc-768x394.png 768w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/python-email-bcc-cc.png 1084w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"smtp-files\">How to Send Python FastAPI Emails With Attached Files?<\/h2>\n\n\n\n<p>We can send emails with files by <a href=\"https:\/\/docs.python.org\/3\/library\/email.mime.html#email.mime.application.MIMEApplication\"><code>MIMEApplication<\/code><\/a> class. The&nbsp;<a href=\"https:\/\/docs.python.org\/3\/library\/email.mime.html#email.mime.application.MIMEApplication\"><code>MIMEApplication<\/code><\/a>&nbsp;class is used&nbsp;to encode nontext characters.  It is encoding to base64.  Read file data and store data in the <strong>MIMEApplication<\/strong> object.  Attach multiple files by file array iteration. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom fastapi import FastAPI\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.application import MIMEApplication\nfrom os.path import basename\n\napp = FastAPI()\n\nport = 2525 \nsmtp_server = &quot;smtp.mailmug.net&quot;\nlogin = &quot;user&quot; # paste your login generated by mailmug\npassword = &quot;pass&quot; # paste your password generated by mailmug\n\nsender_email = &quot;mailmug@example.com&quot;\nreceiver_email =  &#x5B;&quot;new@example.com&quot;, &quot;new1@example.com&quot;]\nmessage = MIMEMultipart(&quot;alternative&quot;)\nmessage&#x5B;&quot;Subject&quot;] = &quot;Test subject&quot;\nmessage&#x5B;&quot;From&quot;] = sender_email\n\nif isinstance(receiver_email, str):\n    message&#x5B;&quot;To&quot;] = receiver_email\nelse:\n    message&#x5B;&quot;To&quot;] = &quot;, &quot;.join(receiver_email)\n\nmessage&#x5B;&quot;Bcc&quot;] = &quot;bcc@example.com&quot;\nmessage&#x5B;&quot;Cc&quot;] = &quot;cc@example.com&quot;\n\n\n@app.get(&quot;\/send-email&quot;)\ndef send_email():\n\n     # write the HTML part\n    html = &quot;&quot;&quot;\\\n        &lt;html&gt;\n        &lt;body&gt;\n            &lt;p&gt;Hi,&lt;br&gt;\n            This is the test email&lt;\/p&gt;\n        &lt;\/body&gt;\n        &lt;\/html&gt;\n        &quot;&quot;&quot;\n    part = MIMEText(html, &quot;html&quot;)\n    message.attach(part)\n\n    files = &#x5B;&#039;path\/to\/my.jpg&#039;]\n    for f in files:\n        with open(f, &quot;rb&quot;) as fil:\n            file_part = MIMEApplication(\n                fil.read(),\n                Name=basename(f)\n            )\n        file_part&#x5B;&#039;Content-Disposition&#039;] = &#039;attachment; filename=&quot;%s&quot;&#039; % basename(f)\n        message.attach(file_part)\n\n    server = smtplib.SMTP(smtp_server, port)\n    server.set_debuglevel(1)\n    server.esmtp_features&#x5B;&#039;auth&#039;] = &#039;LOGIN DIGEST-MD5 PLAIN&#039;\n    server.login(login, password)\n    server.sendmail(\n        sender_email, receiver_email, message.as_string()\n    )\n    server.close()\n\n\n    return {&quot;msg&quot;:&quot;send mail&quot;}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"debug\">Change SMTPlib Debug Option<\/h2>\n\n\n\n<p>The <code><strong>set_debuglevel<\/strong><\/code> method in the <code>smtplib<\/code> the module is used to enable or disable the debug option of the SMTP connection.  It helps to view the data transmission between the SMTP server and the client. <\/p>\n\n\n\n<p><strong>Syntax<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSMTP.set_debuglevel(level)\n<\/pre><\/div>\n\n\n<p><strong>Level<\/strong>: <\/p>\n\n\n\n<p>This is an integer value. The &#8220;0&#8221; means no debug output. 1 stands for basic debug information. 2 provides more debug output.<\/p>\n\n\n\n<div style=\"height:70px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"backgroundtask\">Email With Background Task<\/h2>\n\n\n\n<figure class=\"wp-block-embed is-provider-youtube wp-block-embed-youtube\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"FastAPI Emails in 60 Seconds \u2014 Background Task\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/hC8JSxXvRvQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom fastapi import FastAPI, BackgroundTasks\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\napp = FastAPI()\n\n\n@app.get(&quot;\/&quot;)\ndef read_root():\n    return {&quot;Hello&quot;: &quot;World&quot;}\n\n\n\n@app.get(&quot;\/send-notification&quot;)\nasync def send_notification(background_task: BackgroundTasks):\n    receiver_email = &quot;new@example.com&quot;\n    message = MIMEMultipart(&quot;alternative&quot;)\n    message&#x5B;&quot;Subject&quot;] = &quot;Test subject&quot;\n    message&#x5B;&quot;From&quot;] = sender_email\n    message&#x5B;&quot;To&quot;] = receiver_email\n    \n    background_task.add_task(send_email, message, receiver_email)\n    return {&quot;message&quot;: &quot;Notification sent in the background&quot;}\n\n\nport = 2525\nsmtp_server = &quot;smtp.mailmug.net&quot;\nlogin = &quot;pass&quot; # paste your login generated by mailmug\npassword = &quot;username&quot; # paste your password generated by mailmug\n  \nsender_email = &quot;mailmug@example.com&quot;\n\n\ndef send_email(message, receiver_email):\n  \n     # write the HTML part\n    html = &quot;&quot;&quot;\\\n        &lt;html&gt;\n        &lt;body&gt;\n            &lt;p&gt;Hi,&lt;br&gt;\n            This is the test email&lt;\/p&gt;\n        &lt;\/body&gt;\n        &lt;\/html&gt;\n        &quot;&quot;&quot;\n    part = MIMEText(html, &quot;html&quot;)\n    message.attach(part)\n  \n    server = smtplib.SMTP(smtp_server, port)\n    server.set_debuglevel(1)\n    server.esmtp_features&#x5B;&#039;auth&#039;] = &#039;LOGIN DIGEST-MD5 PLAIN&#039;\n    server.login(login, password)\n    server.sendmail(\n        sender_email, receiver_email, message.as_string()\n    )\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Learn how to send emails using Python FastAPI with step-by-step instructions. This guide includes code examples for sending emails with SMTP, HTML email templates, attachments, to multiple recipients, and more. We are using the Python standard module smtplib. The smtplib is helping to connect the SMTP server and send emails. Navigate to the desired topic [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":204,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.13 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Sending Emails with Python FastAPI: A Quick Guide - MailMug Blog<\/title>\n<meta name=\"description\" content=\"Learn how to send emails using Python FastAPI. Sending emails with SMTP, HTML email templates, attachments, to multiple recipients, and more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mailmug.net\/blog\/fastapi-mail\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sending Emails with Python FastAPI: A Quick Guide - MailMug Blog\" \/>\n<meta property=\"og:description\" content=\"Learn how to send emails using Python FastAPI. Sending emails with SMTP, HTML email templates, attachments, to multiple recipients, and more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mailmug.net\/blog\/fastapi-mail\/\" \/>\n<meta property=\"og:site_name\" content=\"MailMug Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-05T08:44:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-01T06:15:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/fastapi-smtp-email-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mailmug.net\/blog\/fastapi-mail\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/mailmug.net\/blog\/fastapi-mail\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d\"},\"headline\":\"Sending Emails with Python FastAPI: A Quick Guide\",\"datePublished\":\"2023-12-05T08:44:39+00:00\",\"dateModified\":\"2026-01-01T06:15:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mailmug.net\/blog\/fastapi-mail\/\"},\"wordCount\":396,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#organization\"},\"articleSection\":[\"python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/mailmug.net\/blog\/fastapi-mail\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mailmug.net\/blog\/fastapi-mail\/\",\"url\":\"https:\/\/mailmug.net\/blog\/fastapi-mail\/\",\"name\":\"Sending Emails with Python FastAPI: A Quick Guide - MailMug Blog\",\"isPartOf\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#website\"},\"datePublished\":\"2023-12-05T08:44:39+00:00\",\"dateModified\":\"2026-01-01T06:15:00+00:00\",\"description\":\"Learn how to send emails using Python FastAPI. Sending emails with SMTP, HTML email templates, attachments, to multiple recipients, and more.\",\"breadcrumb\":{\"@id\":\"https:\/\/mailmug.net\/blog\/fastapi-mail\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mailmug.net\/blog\/fastapi-mail\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mailmug.net\/blog\/fastapi-mail\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mailmug.net\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sending Emails with Python FastAPI: A Quick Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mailmug.net\/blog\/#website\",\"url\":\"https:\/\/mailmug.net\/blog\/\",\"name\":\"MailMug\",\"description\":\"SandBox SMTP Email Account\",\"publisher\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mailmug.net\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/mailmug.net\/blog\/#organization\",\"name\":\"MailMug\",\"url\":\"https:\/\/mailmug.net\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png\",\"contentUrl\":\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png\",\"width\":320,\"height\":293,\"caption\":\"MailMug\"},\"image\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/mailmug.net\/blog\"],\"url\":\"https:\/\/mailmug.net\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sending Emails with Python FastAPI: A Quick Guide - MailMug Blog","description":"Learn how to send emails using Python FastAPI. Sending emails with SMTP, HTML email templates, attachments, to multiple recipients, and more.","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:\/\/mailmug.net\/blog\/fastapi-mail\/","og_locale":"en_US","og_type":"article","og_title":"Sending Emails with Python FastAPI: A Quick Guide - MailMug Blog","og_description":"Learn how to send emails using Python FastAPI. Sending emails with SMTP, HTML email templates, attachments, to multiple recipients, and more.","og_url":"https:\/\/mailmug.net\/blog\/fastapi-mail\/","og_site_name":"MailMug Blog","article_published_time":"2023-12-05T08:44:39+00:00","article_modified_time":"2026-01-01T06:15:00+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/fastapi-smtp-email-1.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mailmug.net\/blog\/fastapi-mail\/#article","isPartOf":{"@id":"https:\/\/mailmug.net\/blog\/fastapi-mail\/"},"author":{"name":"admin","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d"},"headline":"Sending Emails with Python FastAPI: A Quick Guide","datePublished":"2023-12-05T08:44:39+00:00","dateModified":"2026-01-01T06:15:00+00:00","mainEntityOfPage":{"@id":"https:\/\/mailmug.net\/blog\/fastapi-mail\/"},"wordCount":396,"commentCount":0,"publisher":{"@id":"https:\/\/mailmug.net\/blog\/#organization"},"articleSection":["python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mailmug.net\/blog\/fastapi-mail\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mailmug.net\/blog\/fastapi-mail\/","url":"https:\/\/mailmug.net\/blog\/fastapi-mail\/","name":"Sending Emails with Python FastAPI: A Quick Guide - MailMug Blog","isPartOf":{"@id":"https:\/\/mailmug.net\/blog\/#website"},"datePublished":"2023-12-05T08:44:39+00:00","dateModified":"2026-01-01T06:15:00+00:00","description":"Learn how to send emails using Python FastAPI. Sending emails with SMTP, HTML email templates, attachments, to multiple recipients, and more.","breadcrumb":{"@id":"https:\/\/mailmug.net\/blog\/fastapi-mail\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mailmug.net\/blog\/fastapi-mail\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mailmug.net\/blog\/fastapi-mail\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mailmug.net\/blog\/"},{"@type":"ListItem","position":2,"name":"Sending Emails with Python FastAPI: A Quick Guide"}]},{"@type":"WebSite","@id":"https:\/\/mailmug.net\/blog\/#website","url":"https:\/\/mailmug.net\/blog\/","name":"MailMug","description":"SandBox SMTP Email Account","publisher":{"@id":"https:\/\/mailmug.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mailmug.net\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/mailmug.net\/blog\/#organization","name":"MailMug","url":"https:\/\/mailmug.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png","contentUrl":"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png","width":320,"height":293,"caption":"MailMug"},"image":{"@id":"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/mailmug.net\/blog"],"url":"https:\/\/mailmug.net\/blog\/author\/admin\/"}]}},"amp_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts\/131"}],"collection":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/comments?post=131"}],"version-history":[{"count":66,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":324,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts\/131\/revisions\/324"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/media\/204"}],"wp:attachment":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/media?parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/categories?post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/tags?post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}