Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- # Just simply send an email with out having own SMTP server.
- # It searches the first available on the internet
- # nice isn't it? :)
- #
- from sys import argv
- from email.mime.text import MIMEText
- import smtplib
- from DNS.lazy import mxlookup
- if len(argv) != 5:
- print("Usage : " + argv[0] +" FROM TO SUBJECT MESSAGE")
- print(" FROM is the email address to send from")
- print(" TO is the email address to send to")
- print(" SUBJECT is the email's subject")
- print(" MESSAGE is the message to send")
- else:
- msg = MIMEText(argv[4])
- msg['Subject'] = argv[3]
- msg['To'] = argv[2]
- msg['From'] = argv[1]
- try:
- server = mxlookup(argv[2].split('@')[1])[0][1]
- except:
- print("Error : Could not get an MX record.")
- exit(1)
- print("Connecting to " + server)
- s = smtplib.SMTP(server)
- d = s.sendmail(argv[1], [argv[2]], msg.as_string())
- if len(d) == 0:
- print("Email sent successfully")
- else:
- print("Error occured while sending : " + repr(d))
- s.quit()
- exit(0)
Advertisement
Add Comment
Please, Sign In to add comment