

{"id":110947,"date":"2022-09-05T09:00:52","date_gmt":"2022-09-05T03:30:52","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=110947"},"modified":"2022-09-05T09:36:04","modified_gmt":"2022-09-05T04:06:04","slug":"python-send-emails","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-send-emails\/","title":{"rendered":"How to Send Emails with Python"},"content":{"rendered":"<p>We all send and receive multiple emails every day. When it comes to personal mail, it does not seem much tiresome. But when it comes to sending multiple emails like sending mail when users sign up\u2019s etc., would be tiring when done manually. This is where coding helps you by automating this task of sending emails. In this article, we will be learning to sending emails with different options like formatting, attachments, etc with python. So, let\u2019s get started.<\/p>\n<h3>What is SMTP Server?<\/h3>\n<p>Simple Mail Transfer Protocol (SMTP) is an application layer protocol in the OSI model that lets a user send mail to another person. At the sender\u2019s end it used SMTP connection and at the receiver, this mail is retrieved using protocols POP (Post Office Protocol) and IMAP (Internet Message Access Protocol). The following figure shows the working of SMTP server.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/06\/working-of-smtp-connection.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111072\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/06\/working-of-smtp-connection.webp\" alt=\"working of smtp connection\" width=\"840\" height=\"396\" \/><\/a><\/p>\n<p>Before going to the coding part, let\u2019s see some of the advantages and disadvantages of using SMTP.<\/p>\n<h3>Pros of using SMTP<\/h3>\n<ul>\n<li>It is easy to set up<\/li>\n<li>It is highly cost-effective<\/li>\n<li>It is also platform agnostic<\/li>\n<\/ul>\n<h3>Cons of using SMTP<\/h3>\n<ul>\n<li>It is less secure<\/li>\n<li>And has no built-in analytics<\/li>\n<li>It takes longer send times<\/li>\n<li>And long-term maintenance and uptime burden<\/li>\n<\/ul>\n<h3>Project Prerequisites<\/h3>\n<p>First of all it is a must for the developer to have a mail account for sending a mail.<\/p>\n<p>Also, the Python library smtpib will be used to send the mails in this article and connect to the mail server.<\/p>\n<p>Also, before running the code to login or send mail through Python it is important to give the code access to connect to mail and send emails. This can be done by going to the site https:\/\/myaccount.google.com on your browser logged in with the mail you are using to send the mail.<\/p>\n<h3>Starting connection<\/h3>\n<h4>Using SMTP_SSL()<\/h4>\n<p>One way of connecting to start sending mails through Python is to use SSL connection. Here we create a secure SSL connection and then log in using appropriate credentials.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import smtplib, ssl\r\n\r\nport = 465  # For SSL connection\r\n\r\n# Create a secure SSL context\r\ncontext = ssl.create_default_context()\r\n\r\nwith smtplib.SMTP_SSL(\"smtp.gmail.com\", port, context=context) as server:\r\n    server.login(\"your gmail id\u201d, \u201cpassword\u201d)\r\n    # TODO: Send email here<\/pre>\n<p>Here,<\/p>\n<p>By default the port is zero, if not specified.SMTP_SSL() used standard port for SMTP over SSL (port 465).<br \/>\nsmtplib.SMTP_SSL() as server: makes sure that the connection is automatically closed at the end. If port is zero, or not specified.<\/p>\n<p>You can also use input() or getpass() methods to give the password at the runtime.<\/p>\n<h4>Using .starttls()<\/h4>\n<p>Another method of settingup the connection is by usng starttls().<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import smtplib, ssl\r\n\r\nsender_add='from_address@gmail.com' #the sender's mail id\r\nreceiver_add='to_address@gmail.com' #the receiver's mail id\r\npassword='password' #password to log in\r\n\r\n# Try to log in to server and send email\r\ntry:\r\n    smtp_server=smtplib.SMTP(\"smtp.gmail.com\",587)\r\n    smtp_server.ehlo() #setting up the ESMTP protocol\r\n\r\n    smtp_server.starttls() #setting up the TLS connection\r\n    smtp_server.ehlo() #calling the ehlo() as encryption happens on calling startttls()\r\n\r\n    smtp_server.login(sender_add,password) #logging into the sender's email id\r\n\r\nexcept Exception as e:\r\n    # Print any error message\r\n    print(e)\r\nfinally:\r\n    server.quit()<\/pre>\n<p>In the above code,<\/p>\n<ul>\n<li>We first import the smtplib module<\/li>\n<li>Then, start by setting up the connection with gmail\u2019s SMTP server by creating the SMTP() object. Here, if the port is zero, or not specified, the standard port for SMTP over SSL (port 465).<\/li>\n<li>Then we encrypt the SMTP server using .starttls().<\/li>\n<li>After this, we log in the mail using the correct credentials, gmail account and password.<\/li>\n<\/ul>\n<h3>Sending a Plain Text Email<\/h3>\n<p>Now, let\u2019s discuss the coding part, starting by sending an email with some text.<\/p>\n<h4>Using SMTP_SSL():<\/h4>\n<p>Let\u2019s first see the SMTP_SSL() method to send plain text.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import smtplib, ssl\r\n\r\nport = 465  # For SSL\r\nsmtp_server = \"smtp.gmail.com\"\r\nsender_add='from_address@gmail.com' #the sender's mail id\r\nreceiver_add='to_address@gmail.com' #the receiver's mail id\r\npassword='password' #password to log in\r\n\r\nmsg_to_be_sent ='''\r\nHello, receiver!\r\nHope you are doing well.\r\nWelcome to DataFlair!\r\n'''\r\n\r\ncontext = ssl.create_default_context()\r\nwith smtplib.SMTP_SSL(smtp_server, port, context=context) as server:\r\n    server.login(sender_add, password)\r\n    server.sendmail(sender_add, receiver_add, msg_to_be_sent )\r\n<\/pre>\n<p>Here,<\/p>\n<ul>\n<li>login() method is used to log in to the email<\/li>\n<li>And sendmail() is used to send the mail from receiver_add to sender_add the required message.<\/li>\n<\/ul>\n<h4>Using .starttls()<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import smtplib\r\n\r\nsender_add='from_address@gmail.com' #the sender's mail id\r\nreceiver_add='to_address@gmail.com' #the receiver's mail id\r\npassword='password' #password to log in\r\n\r\n #creating the SMTP server object with SMPT server address and port number\r\nsmtp_server=smtplib.SMTP(\"smtp.gmail.com\",587)\r\nsmtp_server.ehlo() #setting up the ESMTP protocol\r\n\r\nsmtp_server.starttls() #setting up the TLS connection\r\nsmtp_server.ehlo() #calling the ehlo() as encryption happens on calling startttls()\r\n\r\nsmtp_server.login(sender_add,password) #logging into the sender's email id\r\n\r\nmsg_to_be_sent ='''\r\nHello, receiver!\r\nHope you are doing well.\r\nWelcome to DataFlair!\r\n'''\r\n\r\n#sending the mail from specified and to mentioned email address and the message\r\nsmtp_server.sendmail(sender_add,receiver_add,msg_to_be_sent)\r\nsmtp_server.quit()#terminating the server\r\n<\/pre>\n<p>Here,<\/p>\n<ul>\n<li>Here we login to the TLS connection.<\/li>\n<li>And then send the mail with a message using the .sendmail() function to the receiver and finally, quit the server setup.<\/li>\n<\/ul>\n<h4>Sending Fancy Mails with HTML<\/h4>\n<p>Sometimes we try to format the content we send with spaces, adding links, etc. This can be done again in coding with the help of HTML. Also, subject is an important part of an email. Here we use the MIMEMultipart() object.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import smtplib\r\nfrom email.mime.text import MIMEText\r\nfrom email.mime.multipart import MIMEMultipart\r\n\r\nsender_add='from_address@gmail.com' #the sender's mail id\r\nreceiver_add='to_address@gmail.com' #the receiver's mail id\r\npassword='password' #password to log in\r\n\r\n #creating the SMTP server object with SMPT server address and port number\r\nsmtp_server=smtplib.SMTP(\"smtp.gmail.com\",587)\r\nsmtp_server.ehlo() #setting up the ESMTP protocol\r\n\r\nbody = MIMEMultipart(\"alternative\")\r\nbody[\"Subject\"] = \"Multiple messages\"\r\nbody[\"From\"] = sender_add\r\nbody[\"To\"] = receiver_add\r\n\r\nmsg ='''\r\nHello, receiver!\r\nHope you are doing well.\r\nWelcome to DataFlair!\r\n'''\r\n\r\nhtml_msg=\"\"\"&lt;html&gt;\r\n  &lt;body&gt;\r\n    &lt;p&gt;Hello, receiver!&lt;br&gt;\r\n       Hope you are doing well.&lt;br&gt;\r\n       Welcome to &lt;a href=\"https:\/\/data-flair.training\"&gt;DataFlair&lt;\/a&gt; !\r\n    &lt;\/p&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\"\"\"\r\n\r\n# Turn the above information into plain\/html MIMEText objects\r\npart1 = MIMEText(msg, \"plain\")\r\npart2 = MIMEText(html_msg, \"html\")\r\n\r\n# Add HTML\/plain-text parts to MIMEMultipart message\r\n# The email client will try to render the last part first\r\nbody.attach(part1)\r\nbody.attach(part2)\r\n\r\n\r\nsmtp_server.starttls() #setting up the TLS connection\r\nsmtp_server.ehlo() #calling the ehlo() as encryption happens on calling startttls()\r\n\r\nsmtp_server.login(sender_add,password) #logging into the sender's email id\r\n#sending the mail from specified and to mentioned email address and the message\r\nsmtp_server.sendmail(sender_add,receiver_add,body.as_string())\r\nsmtp_server.quit()#terminating the server<\/pre>\n<p>In the above code, we follow a similar procedure we followed above.<\/p>\n<ul>\n<li>First, we set up the SMTP connection<\/li>\n<li>After this, we create the MIMEMultipart() object to combine the text of different format. And then set the subject, from and to address.<\/li>\n<li>Then create the html and plain text using MIMEText() object and combine the information.<\/li>\n<li>Finally, we login, send the mail with the MIMEMultipart() content as string and quit the server.<\/li>\n<\/ul>\n<h3>Sending Mail with an Attachment<\/h3>\n<p>Most of the mails have one\/more attachment(s) like PDFs, images, etc. along with content. And this is what we will do now!<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import email, smtplib, ssl\r\nfrom email import encoders\r\nfrom email.mime.base import MIMEBase\r\nfrom email.mime.multipart import MIMEMultipart\r\nfrom email.mime.text import MIMEText\r\n\r\nsender_add='from_address@gmail.com' #the sender's mail id\r\nreceiver_add='to_address@gmail.com' #the receiver's mail id\r\npassword='password' #password to log in\r\n\r\n #creating the SMTP server object with SMPT server address and port number\r\nsmtp_server=smtplib.SMTP(\"smtp.gmail.com\",587)\r\nsmtp_server.ehlo() #setting up the ESMTP protocol\r\n\r\nbody = MIMEMultipart(\"alternative\")\r\nbody[\"Subject\"] = \"Sending an Attachment\"\r\nbody[\"From\"] = sender_add\r\nbody[\"To\"] = receiver_add\r\n\r\nmsg ='''\r\nHello, receiver!\r\nWe are sending an attachment from  DataFlair!\r\n'''\r\n\r\n# Turn the above information into plain\/html MIMEText objects\r\npart1 = MIMEText(msg, \"plain\")\r\n\r\n# Add HTML\/plain-text parts to MIMEMultipart message\r\n# The email client will try to render the last part first\r\nbody.attach(part1)\r\nfilepath = r\"python.jfif\"\r\n\r\n# Open PDF file in binary mode\r\nwith open(filepath, \"rb\") as attachment:\r\n    # Add file as application\/octet-stream\r\n    # Email client can usually download this automatically as attachment\r\n    file = MIMEBase(\"application\", \"octet-stream\")\r\n    file.set_payload(attachment.read())\r\n\r\n# Encode file in ASCII characters to send by email    \r\nencoders.encode_base64(file)\r\n\r\n# Add header as key\/value pair to attachment part\r\nfile.add_header(\r\n    \"Python Image\",\r\n    f\"attachment; filename= {filepath}\",\r\n)\r\n\r\n# Add attachment to message and convert message to string\r\nbody.attach(file)\r\ntext = body.as_string()\r\n\r\n# Log in to server using secure context and send email\r\ncontext = ssl.create_default_context()\r\n\r\nsmtp_server.starttls() #setting up the TLS connection\r\nsmtp_server.ehlo() #calling the ehlo() as encryption happens on calling startttls()\r\n\r\nsmtp_server.login(sender_add,password) #logging into the sender's email id\r\n#sending the mail from specified and to mentioned email address and the message\r\nsmtp_server.sendmail(sender_add,receiver_add,body.as_string())\r\nsmtp_server.quit()#terminating the server\r\n<\/pre>\n<p>We again use the MIMEMultipart() object to combine the text and the file. Let\u2019s look at the flow of the code to understand more:<\/p>\n<ul>\n<li>Starting with we setup the SMTP connection with the SMTP() object.<\/li>\n<li>Then we create the MIMEMultipart() object with subject, from and to address. And attach the content as MIMEText().<\/li>\n<li>After this, we open the file required to attach in binary mode and create the MIMEBase() object with this file.<\/li>\n<li>And then encode the file and attach it to the body.<\/li>\n<li>Then create the starttls() connection, login, send the main and quit the server.<\/li>\n<\/ul>\n<h3>Sending Multiple Mails<\/h3>\n<p>We also send mails to multiple people and it would obviously be hard to send the mails separately. And we will now learn to send multiple mails at a single shot!<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import csv, smtplib, ssl\r\n\r\nsender_add='from_address@gmail.com' #the sender's mail id\r\nreceiver_add='to_address@gmail.com' #the receiver's mail id\r\npassword='password' #password to log in\r\n\r\n\r\n #creating the SMTP server object with SMPT server address and port number\r\nsmtp_server=smtplib.SMTP(\"smtp.gmail.com\",587)\r\nsmtp_server.ehlo() #setting up the ESMTP protocol\r\n\r\nmessage = \"\"\"Subject: Results\r\n\r\nHello {name}! Your grade for the exam is {grade}\"\"\"\r\n\r\n\r\ncontext = ssl.create_default_context()\r\n\r\nsmtp_server.starttls() #setting up the TLS connection\r\nsmtp_server.ehlo() #calling the ehlo() as encryption happens on calling startttls()\r\n\r\nsmtp_server.login(sender_add,password) #logging into the sender's email id\r\n#sending the mail from specified and to mentioned email address and the message mentioned in the csv\r\nwith open(r\"C:\\Users\\DELL\\Downloads\\grades.csv\") as file:\r\n        reader = csv.reader(file)\r\n        next(reader)  # Skip header row\r\n        for name, email, grade in reader:\r\n            smtp_server.sendmail(\r\n                sender_add,\r\n                email,\r\n                message.format(name=name,grade=grade),\r\n            )\r\nsmtp_server.quit()#terminating the server\r\n<\/pre>\n<p>Here,<\/p>\n<ul>\n<li>We set up the SMTP connection and then create the TLS connection.<\/li>\n<li>We use string formatting to send personalized emails.<\/li>\n<li>And then log in the mail with the sender\u2019s address and password.<\/li>\n<li>We create a CSV file with the name, mail id, and any other information required. Here we store the grades of each user as shown in the figure below.<\/li>\n<li>And then open the file and loop every user and send the mail to every user in the CSV. Here we substitute the name and grade in the file in the formatted string in the place of {name} and {grade}.<\/li>\n<li>Finally, quit the server.<\/li>\n<\/ul>\n<h3>API Way<\/h3>\n<p>Using APIs is another simple approach to send emails. This type of service can be free. Let\u2019s see a coding example to make it clear.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import requests\r\n\r\ndef send_simple_email():\r\n  return requests.post(\r\n    \"CREDENTIALS GIVEN BY MAILGUN\",\r\n    auth=(\"api\", \"CREDENTIALS GIVEN BY MAILGUN\"),\r\n    data={\"from\": \" &lt;your_email@gmail.com&gt;\",\r\n      \"to\": \"Fran\u00e7ois &lt;receiver_email@gmail.com&gt;\",\r\n      \"subject\": \"Subject\",\r\n      \"text\": \"Hello! This is a test email from Dataflair.\"})\r\n\r\n\r\nsend_simple_email()<\/pre>\n<h3>Yagmail<\/h3>\n<p>Python provides multiple libraries to send emails with simple code. Yagmail is one of them, which is specifically for gmails. Let\u2019s look into this library by sending a mail with content and an attachment.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import yagmail\r\nsender_add='from_address@gmail.com' #the sender's mail id\r\nreceiver_add='to_address@gmail.com' #the receiver's mail id\r\npassword='password' #password to log in\r\n\r\nmsg ='''\r\nHello, receiver!\r\nWe are sending an attachment from  DataFlair!\r\n'''\r\nfilename = r\"python.jfif\"\r\n\r\nyag = yagmail.SMTP(sender_add,password)\r\nyag.send(\r\n    to=receiver_add,\r\n    subject=\"Yagmail from DataFlair\",\r\n    contents=msg,\r\n    attachments=filename,\r\n)\r\n<\/pre>\n<p>Seems to be a simpler code right! The yagmail can be installed using the below command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install yagmail<\/pre>\n<p>Then<\/p>\n<ul>\n<li>We import the library<\/li>\n<li>Then set up the SMTP connection with the sender\u2019s address and password<\/li>\n<li>Then send the mail with the receiver\u2019s address, subject, body, and the file path as an attachment.<\/li>\n<\/ul>\n<h3>Transactional Email Services<\/h3>\n<p>If you are someone who is planning to send a large volume of emails, see email statistics, and want to ensure reliable delivery, then transactional email services is a best option. Although all of these services have paid plans for sending large volumes of emails, they also avail free plans to try them out.<\/p>\n<p><strong>Pros of transactional email services<\/strong><\/p>\n<ul>\n<li>It has features like analytics<\/li>\n<li>It has high delivery rates and speeds<\/li>\n<li>Scalable and reliable<\/li>\n<\/ul>\n<p><strong>Cons of transactional email services<\/strong><\/p>\n<ul>\n<li>The learning curve for new API<\/li>\n<li>It is dependent on third-party intermediary<\/li>\n<\/ul>\n<h3>Conclusion<\/h3>\n<p>We have learned to send secure emails using Python. We discussed setting up an SMTP connection, sending mail, formatting content, adding attachments, and sending multiple personalized emails. We also learned to use the yagmail library to send the mail. And then using transactional email services. Hope it was an informative article. Happy coding<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We all send and receive multiple emails every day. When it comes to personal mail, it does not seem much tiresome. But when it comes to sending multiple emails like sending mail when users&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":111073,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[27110,26506,22734,10827,10828,10829,27129,27109],"class_list":["post-110947","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-project-project-for-beginners","tag-python-easy-project","tag-python-project-for-beginners","tag-python-send-email","tag-python-send-email-via-smtp","tag-python-send-mail","tag-python-smtp","tag-sending-emails-with-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Send Emails with Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn sending emails with python. Learn about SMTP server, starting connection Using SMTP_SSL() and Using .starttls(), sending plain mail etc.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-send-emails\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Send Emails with Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn sending emails with python. Learn about SMTP server, starting connection Using SMTP_SSL() and Using .starttls(), sending plain mail etc.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-send-emails\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-05T03:30:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-05T04:06:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/06\/python-send-email-project.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Send Emails with Python - DataFlair","description":"Learn sending emails with python. Learn about SMTP server, starting connection Using SMTP_SSL() and Using .starttls(), sending plain mail etc.","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:\/\/data-flair.training\/blogs\/python-send-emails\/","og_locale":"en_US","og_type":"article","og_title":"How to Send Emails with Python - DataFlair","og_description":"Learn sending emails with python. Learn about SMTP server, starting connection Using SMTP_SSL() and Using .starttls(), sending plain mail etc.","og_url":"https:\/\/data-flair.training\/blogs\/python-send-emails\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2022-09-05T03:30:52+00:00","article_modified_time":"2022-09-05T04:06:04+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/06\/python-send-email-project.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-send-emails\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-send-emails\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"How to Send Emails with Python","datePublished":"2022-09-05T03:30:52+00:00","dateModified":"2022-09-05T04:06:04+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-send-emails\/"},"wordCount":1225,"commentCount":1,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-send-emails\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/06\/python-send-email-project.webp","keywords":["project project for beginners","python easy project","python project for beginners","Python send Email","Python send Email via SMTP","python send mail","python smtp","Sending Emails With Python"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-send-emails\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-send-emails\/","url":"https:\/\/data-flair.training\/blogs\/python-send-emails\/","name":"How to Send Emails with Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-send-emails\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-send-emails\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/06\/python-send-email-project.webp","datePublished":"2022-09-05T03:30:52+00:00","dateModified":"2022-09-05T04:06:04+00:00","description":"Learn sending emails with python. Learn about SMTP server, starting connection Using SMTP_SSL() and Using .starttls(), sending plain mail etc.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-send-emails\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-send-emails\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-send-emails\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/06\/python-send-email-project.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/06\/python-send-email-project.webp","width":1200,"height":628,"caption":"python send email project"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-send-emails\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"How to Send Emails with Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/110947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=110947"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/110947\/revisions"}],"predecessor-version":[{"id":111074,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/110947\/revisions\/111074"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/111073"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=110947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=110947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=110947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}