{"id":251,"date":"2019-03-06T09:03:41","date_gmt":"2019-03-06T09:03:41","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/python\/?p=251"},"modified":"2020-07-26T09:07:34","modified_gmt":"2020-07-26T09:07:34","slug":"python-sending-smtp-email","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/","title":{"rendered":"Python &#8211; Sending SMTP Email"},"content":{"rendered":"<p>In this chapter, I will teach you how to use Python to send emails. So we would write a simple Python program to send emails to Yahoo, Gmail etc.<\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li><a href=\"#t1\">How SMTP Works<\/a><\/li>\n<li><a href=\"#t2\">Sending an Email<\/a><\/li>\n<li><a href=\"#t3\">How Email is Sent<\/a><\/li>\n<li><a href=\"#t4\">Sending HTML Email in Python<\/a><\/li>\n<li><a href=\"#t5\">Including Attachment to Email<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. How SMTP Works<\/strong><\/h4>\n<p>SMTP stands for Simple Mail Transfer Protocol. You use SMTP to send relay emails between mail servers.<\/p>\n<p>The smtplib module is used for this purpose. So you need to import it. This module defines something called &#8216;SMTP client session object&#8217;. This is an object used for sending email to any mail server on the Internet.<\/p>\n<p>To create an SMTP session object, you use the following syntax:<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">smtplib<\/span>\r\n\r\nsmtpObject <span style=\"color: #333333;\">=<\/span> smtplib<span style=\"color: #333333;\">.<\/span>SMTP(host, portnumber, localhostname)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>The SMTP function takes three parameters: host, portnumber and local_hostname<\/p>\n<p><strong>host<\/strong> &#8211; This is the host running SMTP server. You can either specify the computer name, domain name or IP address<\/p>\n<p><strong>portnumber<\/strong>: This is the port on the server where the SMTP is listening. You can typically use port 25 as the portnumber.<\/p>\n<p><strong>localhostname<\/strong>: This is a situation where the SMTP server is your local machine. In this case, the localhostname is just <em>localhost<\/em> (or your computer name)<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Sending an Email<\/strong><\/h4>\n<p>After creating an SMTP session object, you need to use sendmail method. The sendmail method is an instance method used to send and email.<\/p>\n<p>This method takes three parameters:<\/p>\n<p><strong>sender<\/strong> &#8211; This is a string of the sender email address<\/p>\n<p><strong>recipients<\/strong>\u00a0&#8211;\u00a0 List of recipient email addresses<\/p>\n<p><strong>message<\/strong> &#8211;\u00a0 A string that specified To, subject and body of the email<\/p>\n<p>The code below sends an email to the specified email address<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">smtplib<\/span>\r\n\r\nsender <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">'from@fromdomain.com'<\/span>\r\nrecipients <span style=\"color: #333333;\">=<\/span> [<span style=\"background-color: #fff0f0;\">'to@todomain.com'<\/span>]\r\n\r\nmessage <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\"\"From: Sender Name &lt;from@fromdomain.com&gt;<\/span>\r\n<span style=\"background-color: #fff0f0;\">To: Recipient Name &lt;to@todomain.com&gt;<\/span>\r\n<span style=\"background-color: #fff0f0;\">Subject: Test Email<\/span>\r\n\r\n<span style=\"background-color: #fff0f0;\">This is a sample email sent from Python<\/span>\r\n<span style=\"background-color: #fff0f0;\">\"\"\"<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">try<\/span>:\r\n    smtpObject <span style=\"color: #333333;\">=<\/span> smtplib<span style=\"color: #333333;\">.<\/span>SMTP(<span style=\"background-color: #fff0f0;\">'smtp.gmail.com', 587<\/span>)\r\n    smtpObject<span style=\"color: #333333;\">.<\/span>sendmail(sender, recipients, message)\r\n    <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Email has been sent\"<\/span>)\r\n<span style=\"color: #008800; font-weight: bold;\">except<\/span>:\r\n    <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Error Occured: Email Sending failed\"<\/span>)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. How Email is Sent<\/strong><\/h4>\n<p>First, we import the smtplib. Then we define a sender and a list of recipients. Then we define a multiline message. Note that the message specifies the Sender, the Recipient and the Subject. Now, these three items make up the header and they are each place in separate line.<\/p>\n<p>You can get the hostname from the particular host.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Sending HTML Email in Python<\/strong><\/h4>\n<p>A HTML email is different from plain-text email described above. So this means, you can format using html tags. Even if you use html, everything would be displayed as plain text. Therefore to use formatted text which is called HTML email, you need to add two more headers to the email message.<\/p>\n<p>These headers are: MIME-Version and Content-type. The mime version is set to 1.0 while the Content-type is set to text\/html.<\/p>\n<p>See example below, where we have modified the original code to support HTML email.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">smtplib<\/span>\r\n\r\nsender <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">'from@fromdomain.com'<\/span>\r\nrecipients <span style=\"color: #333333;\">=<\/span> [<span style=\"background-color: #fff0f0;\">'to@todomain.com'<\/span>]\r\n\r\nmessage <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\"\"From: Sender Name &lt;from@fromdomain.com&gt;<\/span>\r\n<span style=\"background-color: #fff0f0;\">To: Recipient Name &lt;to@todomain.com&gt;<\/span>\r\n<span style=\"background-color: #fff0f0;\">Subject: Test Email<\/span>\r\n<span style=\"background-color: #fff0f0;\">MIME-Version: 1.0<\/span>\r\n<span style=\"background-color: #fff0f0;\">Content-type: text\/html<\/span>\r\n\r\n<span style=\"background-color: #fff0f0;\">This is a sample email sent from Python<\/span>\r\n<span style=\"background-color: #fff0f0;\">\"\"\"<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">try<\/span>:\r\n    smtpObject <span style=\"color: #333333;\">=<\/span> smtplib<span style=\"color: #333333;\">.<\/span>SMTP(<span style=\"background-color: #fff0f0;\">'localhost'<\/span>)\r\n    smtpObject<span style=\"color: #333333;\">.<\/span>sendmail(sender, recipients, message)\r\n    <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Email has been sent\"<\/span>)\r\n<span style=\"color: #008800; font-weight: bold;\">except<\/span>:\r\n    <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Error Occured: Email Sending failed\"<\/span>)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. Including Attachments to Email<\/strong><\/h4>\n<p>Just like you can attach files when sending email, you can do same in Python. So to do this, you simple change the Content-type to multipart\/mixed.<\/p>\n<p>After you do this, you also need to specify the text and attachment sections within boundaries.<\/p>\n<p>A boundary begins with\u00a0 two hyphens followed by a number. The number must be unique. You need to fetch the attachment using normal <a href=\"https:\/\/www.kindsonthegenius.com\/python\/18-python-files-io\/\">File Operation.<\/a> I recommend you review <a href=\"https:\/\/www.kindsonthegenius.com\/python\/18-python-files-io\/\">Reading from files<\/a>.<\/p>\n<p>The attached file must be encoded in base64. You can encode using the pack(&#8220;m&#8221;) function.<\/p>\n<p>The complete code for sending an attachment is given below:<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">smtplib<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">base64<\/span>\r\n\r\nfilename <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"D\/test.txt\"<\/span>\r\n\r\n<span style=\"color: #888888;\"># Read  a file from the file system<\/span>\r\nfo <span style=\"color: #333333;\">=<\/span> <span style=\"color: #007020;\">open<\/span>(filename, <span style=\"background-color: #fff0f0;\">\"rb\"<\/span>)\r\nfilecontent <span style=\"color: #333333;\">=<\/span> fo<span style=\"color: #333333;\">.<\/span>read()\r\nencodedcontent <span style=\"color: #333333;\">=<\/span> base64<span style=\"color: #333333;\">.<\/span>b64encode(filecontent)\r\n\r\nsender <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">'python@kindsonthegenius.com'<\/span>\r\nreciever <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">'kindson.admin@gmail.com'<\/span>\r\n\r\nmarker <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"MARKER\"<\/span>\r\n\r\nbody <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\"\"<\/span>\r\n<span style=\"background-color: #fff0f0;\">This an email sent with an attachment from kindsonthegenius.com\/python.<\/span>\r\n<span style=\"background-color: #fff0f0;\">\"\"\"<\/span>\r\n<span style=\"color: #888888;\"># Main headers is defined here.<\/span>\r\nsection1 <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\"\"From: From Person &lt;me@fromdomain.net&gt;<\/span>\r\n<span style=\"background-color: #fff0f0;\">To: To Person &lt;kindson.admin@gmail.com&gt;<\/span>\r\n<span style=\"background-color: #fff0f0;\">Subject: Sending Attachment<\/span>\r\n<span style=\"background-color: #fff0f0;\">MIME-Version: 1.0<\/span>\r\n<span style=\"background-color: #fff0f0;\">Content-Type: multipart\/mixed; boundary=%s<\/span>\r\n<span style=\"background-color: #fff0f0;\">--%s<\/span>\r\n<span style=\"background-color: #fff0f0;\">\"\"\"<\/span> <span style=\"color: #333333;\">%<\/span> (marker, marker)\r\n\r\n<span style=\"color: #888888;\"># The message action is defined here<\/span>\r\nsection2 <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\"\"Content-Type: text\/plain<\/span>\r\n<span style=\"background-color: #fff0f0;\">Content-Transfer-Encoding:8bit<\/span>\r\n\r\n<span style=\"background-color: #fff0f0;\">%s<\/span>\r\n<span style=\"background-color: #fff0f0;\">--%s<\/span>\r\n<span style=\"background-color: #fff0f0;\">\"\"\"<\/span> <span style=\"color: #333333;\">%<\/span> (body,marker)\r\n\r\n<span style=\"color: #888888;\"># The attachment is defined here<\/span>\r\nsection3 <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\"\"Content-Type: multipart\/mixed; name=<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0;\">\\\"<\/span><span style=\"background-color: #fff0f0;\">%s<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0;\">\\\"<\/span>\r\n<span style=\"background-color: #fff0f0;\">Content-Transfer-Encoding:base64<\/span>\r\n<span style=\"background-color: #fff0f0;\">Content-Disposition: attachment; filename=%s<\/span>\r\n\r\n<span style=\"background-color: #fff0f0;\">%s<\/span>\r\n<span style=\"background-color: #fff0f0;\">--%s--<\/span>\r\n<span style=\"background-color: #fff0f0;\">\"\"\"<\/span> <span style=\"color: #333333;\">%<\/span>(filename, filename, encodedcontent, marker)\r\nmessage <span style=\"color: #333333;\">=<\/span> section1 <span style=\"color: #333333;\">+<\/span> section2 <span style=\"color: #333333;\">+<\/span> section3\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">try<\/span>:\r\n    smtpObject <span style=\"color: #333333;\">=<\/span> smtplib<span style=\"color: #333333;\">.<\/span>SMTP(<span style=\"background-color: #fff0f0;\">'localhost'<\/span>)\r\n    smtpObject<span style=\"color: #333333;\">.<\/span>sendmail(sender, reciever, message)\r\n    <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Email has been sent successfully\"<\/span>)\r\n<span style=\"color: #008800; font-weight: bold;\">except<\/span> <span style=\"color: #ff0000; font-weight: bold;\">Exception<\/span>:\r\n    <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Error occured: Email sending failed\"<\/span>)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this chapter, I will teach you how to use Python to send emails. So we would write a simple Python program to send emails &hellip; <\/p>\n","protected":false},"author":395,"featured_media":253,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-251","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python - Sending SMTP Email - Python Tutorials<\/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.kindsonthegenius.com\/python\/python-sending-smtp-email\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python - Sending SMTP Email - Python Tutorials\" \/>\n<meta property=\"og:description\" content=\"In this chapter, I will teach you how to use Python to send emails. So we would write a simple Python program to send emails &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-06T09:03:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-26T09:07:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Sending-SMTP-Email.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"934\" \/>\n\t<meta property=\"og:image:height\" content=\"520\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"headline\":\"Python &#8211; Sending SMTP Email\",\"datePublished\":\"2019-03-06T09:03:41+00:00\",\"dateModified\":\"2020-07-26T09:07:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/\"},\"wordCount\":546,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/wp-content\\\/uploads\\\/sites\\\/8\\\/2019\\\/03\\\/Sending-SMTP-Email.jpg\",\"articleSection\":[\"Python Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/\",\"name\":\"Python - Sending SMTP Email - Python Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/wp-content\\\/uploads\\\/sites\\\/8\\\/2019\\\/03\\\/Sending-SMTP-Email.jpg\",\"datePublished\":\"2019-03-06T09:03:41+00:00\",\"dateModified\":\"2020-07-26T09:07:34+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/wp-content\\\/uploads\\\/sites\\\/8\\\/2019\\\/03\\\/Sending-SMTP-Email.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/wp-content\\\/uploads\\\/sites\\\/8\\\/2019\\\/03\\\/Sending-SMTP-Email.jpg\",\"width\":934,\"height\":520},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-sending-smtp-email\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python &#8211; Sending SMTP Email\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/\",\"name\":\"Python Tutorials\",\"description\":\"Python Tutorial for Programming and Data Science\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/author\\\/kindsonthegenius-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python - Sending SMTP Email - Python Tutorials","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.kindsonthegenius.com\/python\/python-sending-smtp-email\/","og_locale":"en_US","og_type":"article","og_title":"Python - Sending SMTP Email - Python Tutorials","og_description":"In this chapter, I will teach you how to use Python to send emails. So we would write a simple Python program to send emails &hellip;","og_url":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/","og_site_name":"Python Tutorials","article_published_time":"2019-03-06T09:03:41+00:00","article_modified_time":"2020-07-26T09:07:34+00:00","og_image":[{"width":934,"height":520,"url":"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Sending-SMTP-Email.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/python\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"headline":"Python &#8211; Sending SMTP Email","datePublished":"2019-03-06T09:03:41+00:00","dateModified":"2020-07-26T09:07:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/"},"wordCount":546,"commentCount":0,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Sending-SMTP-Email.jpg","articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/","url":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/","name":"Python - Sending SMTP Email - Python Tutorials","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Sending-SMTP-Email.jpg","datePublished":"2019-03-06T09:03:41+00:00","dateModified":"2020-07-26T09:07:34+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Sending-SMTP-Email.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Sending-SMTP-Email.jpg","width":934,"height":520},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/python\/python-sending-smtp-email\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/python\/"},{"@type":"ListItem","position":2,"name":"Python &#8211; Sending SMTP Email"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/python\/#website","url":"https:\/\/www.kindsonthegenius.com\/python\/","name":"Python Tutorials","description":"Python Tutorial for Programming and Data Science","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/python\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/python\/author\/kindsonthegenius-2\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts\/251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/users\/395"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/comments?post=251"}],"version-history":[{"count":3,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts\/251\/revisions"}],"predecessor-version":[{"id":373,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts\/251\/revisions\/373"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/media\/253"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/media?parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/categories?post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/tags?post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}