Created
November 15, 2013 23:23
-
-
Save idlecool/7493415 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import socket | |
| import smtplib | |
| import datetime | |
| REMOTE_SMTP_HOST = "smtp.example.com" | |
| REMOTE_SMTP_LOGIN = "postman@example.com" | |
| REMOTE_SMTP_PASSWORD = "postman_password" | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| sock.settimeout(0.2) | |
| try: | |
| sock.connect(("127.0.0.1",25)) | |
| print "Port is open" | |
| except: | |
| s = smtplib.SMTP() | |
| s.connect(REMOTE_SMTP_HOST, 25) | |
| s.login(REMOTE_SMTP_LOGIN, REMOTE_SMTP_PASSWORD) | |
| fromaddr = "smtp-relay@example.com" | |
| toaddrs = ["dev1@example.com", "dev2@example.com"] | |
| subj = "Salesforce SMTP Relay is down" | |
| text = "Salesforce SMTP Relay is down" | |
| msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % (fromaddr, ", ".join(toaddrs), subj, datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" ), text) | |
| s.sendmail(fromaddr, toaddrs, msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment