- 要求邮件发件人别名为“安全中心”
- 邮件内容为网址https://www.163.com,收件人点击后跳转到Google。
#!/usr/bin/env python3
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import getpass
def send_email():
mail_host = 'smtp.163.com'
mail_user = 'zhenning.shi'
mail_pwd = getpass.getpass("Password:")
sender = '安全中心<zhenning.shi@163.com>'
receive = 'shi.zhenning@im.com'
html = '''\
<html>
<body>
<p>
<a rel="nofollow" href = "https://www.google.com/">https://www.163.com</a>
</p>
</body >
</html>
'''
message = MIMEText(html, "html")
message['subject'] = '安全通知:密码过期,请尽快更改'
message['From'] = sender
message['To'] = receive
smtpobj = smtplib.SMTP()
smtpobj.connect(mail_host, 25)
smtpobj.login(mail_user,mail_pwd)
try:
smtpobj.sendmail(sender,receive,message.as_string())
print('send sucess!')
smtpobj.quit()
except smtplib.SMTPException:
print('send failure!')
if __name__ == '__main__':
send_email()
如提示: