{"id":2348,"date":"2014-05-15T09:12:59","date_gmt":"2014-05-15T13:12:59","guid":{"rendered":"http:\/\/antipaucity.com\/?p=2348"},"modified":"2014-05-15T09:12:59","modified_gmt":"2014-05-15T13:12:59","slug":"sending-email-in-python-with-gmail","status":"publish","type":"post","link":"https:\/\/merikebi.warrenmyers.com\/?p=2348","title":{"rendered":"sending email in python with gmail"},"content":{"rendered":"<p>A {{Python}} nugget from {{Programming Your Home}} (<a href=\"http:\/\/antipaucity.com\/2014\/05\/05\/programming-your-home-by-mike-riley\/#.U17EB-ZdWtY\">review<\/a>) I wanted to share from p97:<\/p>\n<pre>import smtplib\ndef send_email(subject, message)\n    recipient = 'your_email_recipient@domain.tld'\n    gmail_sender = 'your_gmail_account@gmail.com'\n    gmail_password = 'your_gmail_password'\n\n    #use tls\n    gmail_smtp = smtplib.SMTP('smtp.gmail.com', 587)\n    gmail_smtp.ehlo()\n    gmail_smtp.starttls()\n    gmail_smtp.ehlo()\n\n    #login\n    gmail_smtp.login(gmail_send, gmail_password)\n\n    #message formatting\n    mail_header = 'To: ' + recipient + '\\n' + 'From: ' + gmail_sender + '\\n' + 'Subject: ' + subject + '\\n'\n    message_body = message\n    mail message = mail_header + '\\n ' + message_body + '\\n\\n'\n\n    #send\n    gmail_smtp.sendmail(gmail_sender, recipient, mail_message)\n\n    #close\n    gmail_smtp.close()\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A {{Python}} nugget from {{Programming Your Home}} (review) I wanted to share from p97: import smtplib def send_email(subject, message) recipient = &#8216;your_email_recipient@domain.tld&#8217; gmail_sender = &#8216;your_gmail_account@gmail.com&#8217; gmail_password = &#8216;your_gmail_password&#8217; #use tls gmail_smtp = smtplib.SMTP(&#8216;smtp.gmail.com&#8217;, 587) gmail_smtp.ehlo() gmail_smtp.starttls() gmail_smtp.ehlo() #login gmail_smtp.login(gmail_send, gmail_password) #message formatting mail_header = &#8216;To: &#8216; + recipient + &#8216;\\n&#8217; + &#8216;From: &#8216; + gmail_sender &hellip;<br \/><a href=\"https:\/\/merikebi.warrenmyers.com\/?p=2348\" class=\"more-link pen_button pen_element_default pen_icon_arrow_double\">Continue reading <span class=\"screen-reader-text\">sending email in python with gmail<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[6,34,37,41],"tags":[606,687],"keyring_services":[],"class_list":["post-2348","post","type-post","status-publish","format-standard","hentry","category-code","category-quote","category-reprint","category-technical","tag-python","tag-smtp"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts\/2348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2348"}],"version-history":[{"count":0,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts\/2348\/revisions"}],"wp:attachment":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2348"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fkeyring_services&post=2348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}