Created
May 30, 2015 01:32
-
-
Save Zane5/dbb7838535d637eeb5a4 to your computer and use it in GitHub Desktop.
This file contains 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
``` | |
email address: auto_sms@mail.example.cn | |
email passwd: h9LH | |
``` | |
import smtplib | |
import email.utils | |
from email.mime.text import MIMEText | |
import getpass | |
# Prompt the user for connection info | |
to_email = raw_input('Recipient: ') | |
servername = raw_input('Mail server name: ') | |
username = raw_input('Mail user name: ') | |
password = getpass.getpass("%s's password: " % username) | |
# Create the message | |
msg = MIMEText('Test message from send100.PY') | |
msg.set_unixfrom('author') | |
msg['To'] = email.utils.formataddr(('Recipient', to_email)) | |
msg['From'] = email.utils.formataddr(('push600', 'push600@mail.examply.cn')) | |
msg['Subject'] = 'Test from send100.py' | |
server = smtplib.SMTP(servername, 25) | |
try: | |
server.set_debuglevel(True) | |
# identify ourselves, prompting server for supported features | |
server.ehlo() | |
# If we can encrypt this session, do it | |
if server.has_extn('STARTTLS'): | |
server.starttls() | |
server.ehlo() # re-identify ourselves over TLS connection | |
server.login(username, password) | |
server.sendmail('push600@mail.example.cn', [to_email], msg.as_string()) | |
finally: | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment