{"id":75,"date":"2012-11-06T23:14:37","date_gmt":"2012-11-07T07:14:37","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=75"},"modified":"2012-11-06T23:16:10","modified_gmt":"2012-11-07T07:16:10","slug":"python-inject-smtp","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/python-inject-smtp\/","title":{"rendered":"Python Inject SMTP"},"content":{"rendered":"

Sometimes I want to email from Python and this is pretty easy. Or even just testing mail flow I prefer this over good old \"telnet host 25\" since we have well constructed headers with smtplib.<\/p>\n

\r\n#!\/usr\/bin\/python\r\nimport datetime\r\nimport os\r\nimport sys\r\nimport smtplib\r\n\r\ndef warnEmail(SMTPserver, Subject, Body):\r\n fromaddr = \"rrosso@domain.com\"\r\n #toaddrs = [\"rcpt1@domain.com\",\"rcpt2@domain.com\"]\r\n toaddrs = [\"hostmaster@domain.com\"]\r\n\r\n msg = (\"From: %s\\r\\nTo: %s\\r\\nSubject: %s\\r\\n\\r\\n\" % (fromaddr, \", \".join(toaddrs),Subject))\r\n \r\n server = smtplib.SMTP(SMTPserver)\r\n msg = msg + Body\r\n #server.set_debuglevel(1)\r\n server.sendmail(fromaddr, toaddrs, msg)\r\n server.quit()\r\n\r\nSMTPserver =  'mailhost'\r\nwarnEmail(SMTPserver, \"Test through \" + SMTPserver , \"Body test goes \\n here!\")\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

Sometimes I want to email from Python and this is pretty easy. Or even just testing mail flow I prefer<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}