python简单实现注册自动发送邮件
@app.route('/register/', methods=['GET', 'POST'])
def register():if request.method == 'POST':username = request.form.get("username", None)password = request.form.get('password', None)# 当所有的信息遍历结束, 都没有发现注册的用户存在, 则将注册的用户添加到服务器, 并跳转登录界面;for user in users:if user['username'] == username:return render_template('register.html', message="用户%s已经存在" % (username))else:users.append(dict(username=username, password=password))flash("用户%s已经注册成功, 请登录....." % (username), category='info')app.config['MAIL_SERVER'] = 'smtp.qq.com'# 指定端口, 默认25, 但qq邮箱默认为 端口号465或587;
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = '2287236639'
app.config['MAIL_PASSWORD'] = "epddcimhxnfndjcj"to = ['2287236639@qq.com', ]message = 'time:%s \n ip:%s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), socket.gethostbyname(socket.gethostname()))content = MIMEText(message) # MIMEText表示邮件发送具体内容content['Subject'] = 'Python邮箱测试'content['From'] = '2287236639@qq.com'sent.sendmail('2287236639@qq.com', to, content.as_string()) # 三个参数sent.close() # 关闭邮箱
python简单实现注册自动发送邮件
@app.route('/register/', methods=['GET', 'POST'])
def register():if request.method == 'POST':username = request.form.get("username", None)password = request.form.get('password', None)# 当所有的信息遍历结束, 都没有发现注册的用户存在, 则将注册的用户添加到服务器, 并跳转登录界面;for user in users:if user['username'] == username:return render_template('register.html', message="用户%s已经存在" % (username))else:users.append(dict(username=username, password=password))flash("用户%s已经注册成功, 请登录....." % (username), category='info')app.config['MAIL_SERVER'] = 'smtp.qq.com'# 指定端口, 默认25, 但qq邮箱默认为 端口号465或587;
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = '2287236639'
app.config['MAIL_PASSWORD'] = "epddcimhxnfndjcj"to = ['2287236639@qq.com', ]message = 'time:%s \n ip:%s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), socket.gethostbyname(socket.gethostname()))content = MIMEText(message) # MIMEText表示邮件发送具体内容content['Subject'] = 'Python邮箱测试'content['From'] = '2287236639@qq.com'sent.sendmail('2287236639@qq.com', to, content.as_string()) # 三个参数sent.close() # 关闭邮箱