|
@@ -1,80 +1,35 @@
|
|
-# -*- coding:utf-8 -*-
|
|
|
|
-import smtplib
|
|
|
|
-import email
|
|
|
|
-from email.mime.multipart import MIMEMultipart
|
|
|
|
-from email.mime.text import MIMEText
|
|
|
|
-from email.mime.image import MIMEImage
|
|
|
|
-from email.mime.base import MIMEBase
|
|
|
|
-from email.mime.application import MIMEApplication
|
|
|
|
-from email.header import Header
|
|
|
|
-# 发件人地址,通过控制台创建的发件人地址
|
|
|
|
-username = 'message@dvema.com'
|
|
|
|
-# 发件人密码,通过控制台创建的发件人密码
|
|
|
|
-password = 'SMtp123456'
|
|
|
|
-# 自定义的回复地址
|
|
|
|
-replyto = '***'
|
|
|
|
-# 收件人地址或是地址列表,支持多个收件人,最多30个
|
|
|
|
-#rcptto = '***,***'
|
|
|
|
-# rcptto = '1758730877@qq.com'
|
|
|
|
-rcptto = 'cjk1758730877@gmail.com'
|
|
|
|
-# 构建alternative结构
|
|
|
|
-msg = MIMEMultipart('alternative')
|
|
|
|
-msg['Subject'] = Header('自定义信件主题').encode()
|
|
|
|
-msg['From'] = '%s <%s>' % (Header('自定义发信昵称').encode(), username)
|
|
|
|
-# msg['To'] = rcptto
|
|
|
|
-msg['Reply-to'] = replyto
|
|
|
|
-msg['Message-id'] = email.utils.make_msgid()
|
|
|
|
-msg['Date'] = email.utils.formatdate()
|
|
|
|
-# 构建alternative的text/plain部分
|
|
|
|
-# textplain = MIMEText('自定义TEXT纯文本部分', _subtype='plain', _charset='UTF-8')
|
|
|
|
-# msg.attach(textplain)
|
|
|
|
-# 构建alternative的text/html部分
|
|
|
|
-sendHtml = '''
|
|
|
|
-<!DOCTYPE html>
|
|
|
|
-<html lang="en">
|
|
|
|
-<head>
|
|
|
|
- <meta charset="UTF-8">
|
|
|
|
- <title>Title</title>
|
|
|
|
-</head>
|
|
|
|
-<body>
|
|
|
|
-<div class="content"
|
|
|
|
- style="overflow: hidden;padding:30px 10% 70px 10%;margin:0 10%;background-color: #fff;box-shadow:0 4px 20px rgba(0,0,0,0.1);word-break: break-all;">
|
|
|
|
- <h2 style="margin: 30px 0;">Hello, {username}</h2>
|
|
|
|
- <p style="margin-bottom: 40px;">请输入验证码完成注册,有效期10分钟:</p>
|
|
|
|
- <span style="padding: 10px 20px; font-size: 24px;background-color: #EB6F5A;border-radius:4px;color:#fff;">{captcha}</span>
|
|
|
|
-</div>
|
|
|
|
-</body>
|
|
|
|
-</html>
|
|
|
|
-'''
|
|
|
|
-texthtml = MIMEText(sendHtml, _subtype='html', _charset='UTF-8')
|
|
|
|
-msg.attach(texthtml)
|
|
|
|
-# 发送邮件
|
|
|
|
-try:
|
|
|
|
- client = smtplib.SMTP()
|
|
|
|
- #python 2.7以上版本,若需要使用SSL,可以这样创建client
|
|
|
|
- #client = smtplib.SMTP_SSL()
|
|
|
|
- #SMTP普通端口为25或80
|
|
|
|
- client.connect('smtpdm.aliyun.com', 25)
|
|
|
|
- #开启DEBUG模式
|
|
|
|
- client.set_debuglevel(0)
|
|
|
|
- client.login(username, password)
|
|
|
|
- #发件人和认证地址必须一致
|
|
|
|
- #备注:若想取到DATA命令返回值,可参考smtplib的sendmaili封装方法:
|
|
|
|
- # 使用SMTP.mail/SMTP.rcpt/SMTP.data方法
|
|
|
|
- client.sendmail(username, rcptto, msg.as_string())
|
|
|
|
- client.quit()
|
|
|
|
- print('邮件发送成功')
|
|
|
|
-except smtplib.SMTPConnectError as e:
|
|
|
|
- print('邮件发送失败,连接失败:', e.smtp_code, e.smtp_error)
|
|
|
|
-except smtplib.SMTPAuthenticationError as e:
|
|
|
|
- print('邮件发送失败,认证错误:', e.smtp_code, e.smtp_error)
|
|
|
|
-except smtplib.SMTPSenderRefused as e:
|
|
|
|
- print('邮件发送失败,发件人被拒绝:', e.smtp_code, e.smtp_error)
|
|
|
|
-except smtplib.SMTPRecipientsRefused as e:
|
|
|
|
- print('邮件发送失败,收件人被拒绝:', e.smtp_code, e.smtp_error)
|
|
|
|
-except smtplib.SMTPDataError as e:
|
|
|
|
- print('邮件发送失败,数据接收拒绝:', e.smtp_code, e.smtp_error)
|
|
|
|
-except smtplib.SMTPException as e:
|
|
|
|
- print('邮件发送失败, ', e.message)
|
|
|
|
-except Exception as e:
|
|
|
|
- print('邮件发送异常, ', str(e))
|
|
|
|
|
|
+class Stack(object):
|
|
|
|
+ """栈"""
|
|
|
|
+ def __init__(self):
|
|
|
|
+ self.items = []
|
|
|
|
+
|
|
|
|
+ def is_empty(self):
|
|
|
|
+ """判断是否为空"""
|
|
|
|
+ return self.items == []
|
|
|
|
+
|
|
|
|
+ def push(self, item):
|
|
|
|
+ """加入元素"""
|
|
|
|
+ self.items.append(item)
|
|
|
|
+
|
|
|
|
+ def pop(self):
|
|
|
|
+ """弹出元素"""
|
|
|
|
+ return self.items.pop()
|
|
|
|
+
|
|
|
|
+ def peek(self):
|
|
|
|
+ """返回栈顶元素"""
|
|
|
|
+ return self.items[len(self.items)-1]
|
|
|
|
+
|
|
|
|
+ def size(self):
|
|
|
|
+ """返回栈的大小"""
|
|
|
|
+ return len(self.items)
|
|
|
|
+
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
+ stack = Stack()
|
|
|
|
+ stack.push("hello")
|
|
|
|
+ stack.push("world")
|
|
|
|
+ stack.push("itcast")
|
|
|
|
+ print(stack.size())
|
|
|
|
+ print(stack.peek())
|
|
|
|
+ print(stack.pop())
|
|
|
|
+ print(stack.pop())
|
|
|
|
+ print(stack.pop())
|