Skip to content

Instantly share code, notes, and snippets.

@zhangyangjing
Last active September 26, 2017 01:24
Show Gist options
  • Save zhangyangjing/8644781 to your computer and use it in GitHub Desktop.
Save zhangyangjing/8644781 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# coding=utf-8
import smtplib
from email.mime.text import MIMEText
class Sms(object):
def __init__(self, mail_host, mail_user, mail_pswd):
self._mail_host = mail_host
self._mail_user = mail_user
self._mail_pswd = mail_pswd
self._send_address = '%s<%s>' % (self._mail_user, self._mail_user)
def send(self, mail_address, subject, content):
target_address = '%s<%s>' % (mail_address, mail_address)
msg = MIMEText(content)
msg['Subject'] = subject
msg['From'] = self._mail_user
msg['to'] = target_address
try:
stp = smtplib.SMTP()
stp.connect(self._mail_host)
stp.login(self._mail_user, self._mail_pswd)
stp.sendmail(self._send_address, target_address, msg.as_string())
stp.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
sms = Sms('smtp.exmail.qq.com', '***@qq.com', '**pswd**')
r = sms.send('1364546****@139.com', 'klk', 'k')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment