import smtplib
from email.mime.text import MIMEText
smtp_server = 'smtp.aliyun.com'
smtp_port = 465
email_user = '你的邮箱'
email_password = '你的授权码'
msg = MIMEText('你的验证码是:123456
', 'html', 'utf-8')
msg['From'] = email_user
msg['To'] = '用户邮箱'
msg['Subject'] = '您的注册验证码'
try:
server = smtplib.SMTP_SSL(smtp_server, smtp_port)
server.login(email_user, email_password)
server.sendmail(email_user, ['用户邮箱'], msg.as_string())
print('验证码已发送!')
except Exception as e:
print('出错啦:', e)
finally:
server.quit()
是不是看着就像在放烟花?咱们还可以结合前端色彩鲜明的验证码输入框,让用户在页面上“嗖”一下输入验证码,方便得不要不要的。这就像网购的确认订单一样,得让操作流畅顺滑,不容反悔!