{"id":4673,"date":"2021-07-26T04:47:28","date_gmt":"2021-07-26T04:47:28","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=4673"},"modified":"2021-07-26T05:06:50","modified_gmt":"2021-07-26T05:06:50","slug":"send-an-email-using-the-aws-ses-in-python-boto3-module","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/","title":{"rendered":"Send an email using the AWS SES in Python (Boto3 module)"},"content":{"rendered":"<ol>\n<li>\n<h2>Prerequisites<\/h2>\n<p>Before you begin, perform the following tasks:<\/p>\n<ul>\n<li>Verify your email address with Amazon SES\u2014Before you can send an email with Amazon SES, you must verify that you own the sender&#8217;s email address. If your account is still in the Amazon SES sandbox, you must also verify the recipient\u2019s email address. The easiest way to verify email addresses is by using the Amazon SES console.<\/li>\n<li>Get your <em>AWS credentials\u2014You need an AWS access key<\/em> ID and AWS secret access key to access Amazon SES using an SDK. You can find your credentials by using the Security Credentials page of the AWS Management Console. For more information about credentials, see Types of <a href=\"https:\/\/studysection.com\/blog\/brief-history-of-amazon-group-of-companies\/\">Amazon SES<\/a> credentials.<\/li>\n<li>Install Python\u2014Python is available at https:\/\/www.python.org\/downloads\/. After you install Python, add the path to Python in your environment variables so that you can run Python from any command prompt.<\/li>\n<li>Install the AWSCLI module for Python (Boto3)\u2014For download the module command is:<br \/>\n<code>PIP INSTALL AWSCLI.<\/code><\/li>\n<li>Add These Credentials\u2014For adding these open the cmd in your pc then follow these commands:<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/07\/cmd.png\" alt=\"cmd\" \/>\n<\/li>\n<li>In the above example, it is necessary to fill the AWS Access Key and Secret Access Key and others are optional like region and output format.<\/li>\n<\/ul>\n<\/li>\n<li>\n<h3>Procedure for Amazon SES email through Python<\/h3>\n<p><strong>The following procedure shows how to send an email through Amazon SES.<\/strong><\/p>\n<p>To send an email through Amazon SES In a text editor, create a file named amazon-ses-sample.py. Paste the following code into the file:<br \/>\n<em>Python program<\/em><br \/>\n<code>import boto3<br \/>\nfrom botocore.exceptions import ClientError<br \/>\nimport random<br \/>\n#Replace sender@example.com with your \"From\" address.<br \/>\n# This address must be verified with Amazon SES.<br \/>\nSENDER = \u201cservice@hellodomain.com\u201d<br \/>\n# Replace recipient@example.com with a \"To\" address. If your account<br \/>\n# is still in the sandbox, this address must be verified.<br \/>\nRECIPIENT = \u201cuser@hellodomain.com\u201d<br \/>\n# # Specify a configuration set. If you do not want to use a configuration<br \/>\n# # set, comment the following variable, and the<br \/>\n# # ConfigurationSetName=CONFIGURATION_SET argument below.<br \/>\n# CONFIGURATION_SET = \"ConfigSet\"<br \/>\n# If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES.<br \/>\nAWS_REGION = \"us-east-2\"<br \/>\n# The subject line for the email.<br \/>\nSUBJECT = \u201cWinsurTech Support Team\u201d<br \/>\nOtp=random.randint(100000,999999)<br \/>\n# The email body for recipients with non-HTML email clients.<br \/>\n# BODY_TEXT = (\"Amazon SES Test (Python)\\r\\n\"<br \/>\n#             \"This email was sent with Amazon SES using the \"<br \/>\n#             \"AWS SDK for Python (Boto). text part\"<br \/>\n#             )<br \/>\n# The HTML body of the email.<br \/>\nBODY_HTML = \"\"\"&lt;html><br \/>\n&lt;head>&lt;\/head><br \/>\n&lt;body><br \/>\n&lt;h1>\"\"\"+SUBJECT+\"\"\"&lt;\/h1><br \/>\n&lt;p> Otp for your account verification is \"\"\"+str(otp)+\"\"\" .&lt;br> &lt;br><br \/>\nThanks, &lt;br><br \/>\nWinsurTech Support Team &lt;br><br \/>\nservice@hellodomain.com &lt;br><br \/>\n&lt;\/p><br \/>\n&lt;\/body><br \/>\n&lt;\/html><br \/>\n\"\"\"<br \/>\n # The character encoding for the email.<br \/>\nCHARSET = \"UTF-8\"<br \/>\n# Create a new SES resource and specify a region.<br \/>\nclient = boto3.client('ses',region_name=AWS_REGION)<br \/>\n# Try to send the email.<br \/>\ntry:<br \/>\n#Provide the contents of the email.<br \/>\nresponse = client.send_email(<br \/>\n Destination={<br \/>\n'ToAddresses': [<br \/>\nRECIPIENT,<br \/>\n],<br \/>\n },<br \/>\nMessage={<br \/>\n'Body': {<br \/>\n'Html': {<br \/>\n'Charset': CHARSET,<br \/>\n'Data': BODY_HTML,<br \/>\n},<br \/>\n'Text': {<br \/>\n'Charset': CHARSET,<br \/>\n'Data': \"\",<br \/>\n},<br \/>\n},<br \/>\n'Subject': {<br \/>\n'Charset': CHARSET,<br \/>\n'Data': SUBJECT,<br \/>\n},<br \/>\n},<br \/>\nSource=SENDER,<br \/>\n# # If you are not using a configuration set, comment or delete the<br \/>\n# # following line<br \/>\n# ConfigurationSetName=CONFIGURATION_SET,<br \/>\n)<br \/>\n# Display an error if something goes wrong.<br \/>\nexcept ClientError as e:<br \/>\nprint(e.response['Error']['Message'])<br \/>\n   else:<br \/>\nprint(\"Email sent! Message ID:\"),<br \/>\nprint(response['MessageId'])<\/code>\n<\/li>\n<ul>\n<li><strong>service@hellodomain.com\u2014<\/strong> Replace with an email address that you have verified with Amazon SES. For more information, Email addresses in Amazon SES are case-sensitive. Make sure that the address you enter is exactly the same as the one you verified.<\/li>\n<li><strong>user@hellodomain.com\u2014<\/strong> Replace with the address of the recipient. If your account is still in the sandbox, you must verify this address before you use it. Make sure that the address you enter is exactly the same as the one you verified.<\/li>\n<li><strong>(Optional) us-east-2\u2014<\/strong> If you want to use Amazon SES in a region other than US West (Oregon), replace this with the region you want to use.<\/li>\n<li>Save amazon-ses-sample.py.<\/li>\n<li>To run the program, open a command prompt in the same directory as amazon-ses-sample.py, and then type python amazon-ses-sample.py<\/li>\n<li>Review the output. If the email was successfully sent, the console displays &#8220;Email sent!&#8221; Otherwise, it displays an error message.<\/li>\n<li>Sign in to the email client of the recipient\u2019s address. You will find the message that you sent.<\/li>\n<\/ul>\n<\/ol>\n<p><small><em>If you need to prove your skills in the .NET framework, get .NET certified on StudySection. StudySection provides <a href=\"https:\/\/www.studysection.com\/c-sharp-net-azure-web-developer-advanced-diploma\">.NET Certification Exam<\/a> for beginners as well as experts in the .NET framework. This .NET certification can improve your resume\u2019s success rate.<\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisites Before you begin, perform the following tasks: Verify your email address with Amazon SES\u2014Before you can send an email<\/p>\n","protected":false},"author":1,"featured_media":4674,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[63,33],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Send an email using the AWS SES in Python - StudySection Blog<\/title>\n<meta name=\"description\" content=\"After you install Python, add the path to Python in your environment variables so that you can run it from any command prompt.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Send an email using the AWS SES in Python - StudySection Blog\" \/>\n<meta property=\"og:description\" content=\"After you install Python, add the path to Python in your environment variables so that you can run it from any command prompt.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-26T04:47:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-26T05:06:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/07\/Python-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\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:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Send an email using the AWS SES in Python (Boto3 module)\",\"datePublished\":\"2021-07-26T04:47:28+00:00\",\"dateModified\":\"2021-07-26T05:06:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/\"},\"wordCount\":476,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"AWS\",\"Python\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/\",\"url\":\"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/\",\"name\":\"Send an email using the AWS SES in Python - StudySection Blog\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2021-07-26T04:47:28+00:00\",\"dateModified\":\"2021-07-26T05:06:50+00:00\",\"description\":\"After you install Python, add the path to Python in your environment variables so that you can run it from any command prompt.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Send an email using the AWS SES in Python (Boto3 module)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Send an email using the AWS SES in Python - StudySection Blog","description":"After you install Python, add the path to Python in your environment variables so that you can run it from any command prompt.","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:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/","og_locale":"en_US","og_type":"article","og_title":"Send an email using the AWS SES in Python - StudySection Blog","og_description":"After you install Python, add the path to Python in your environment variables so that you can run it from any command prompt.","og_url":"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2021-07-26T04:47:28+00:00","article_modified_time":"2021-07-26T05:06:50+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/07\/Python-1.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Send an email using the AWS SES in Python (Boto3 module)","datePublished":"2021-07-26T04:47:28+00:00","dateModified":"2021-07-26T05:06:50+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/"},"wordCount":476,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["AWS","Python"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/","url":"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/","name":"Send an email using the AWS SES in Python - StudySection Blog","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2021-07-26T04:47:28+00:00","dateModified":"2021-07-26T05:06:50+00:00","description":"After you install Python, add the path to Python in your environment variables so that you can run it from any command prompt.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/send-an-email-using-the-aws-ses-in-python-boto3-module\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Send an email using the AWS SES in Python (Boto3 module)"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":4892,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4673"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=4673"}],"version-history":[{"count":5,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4673\/revisions"}],"predecessor-version":[{"id":4681,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4673\/revisions\/4681"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/4674"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=4673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=4673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=4673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}