import smtplib
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from urllib.parse import quote
email = MIMEMultipart()
email['From'] = '396434855@qq.com'
email['To'] = '484439767@qq.com'
email['Subject'] = Header('test', 'utf-8')
content = """<p>亲爱的前同事:</p>
<p>你需要的离职证明在附件中,请查收!</p>
<br>
<p>祝,好!</p>
<hr>
<p>孙美丽 即日</p>"""
email.attach(MIMEText(content, 'html', 'utf-8'))
with open(f'王大锤离职证明.docx', 'rb') as file:
attachment = MIMEText(file.read(), 'base64', 'gbk')
attachment['content-type'] = 'application/octet-stream'
filename = quote('王大锤离职证明.docx')
attachment['content-disposition'] = f'attachment; filename="{filename}"'
email.attach(attachment)
smtp_obj = smtplib.SMTP_SSL('smtp.qq.com', 465)
smtp_obj.login('396434855@qq.com', 'tesyfqhfuofqcaee')
smtp_obj.sendmail(
'396434855@qq.com',
'484439767@qq.com',
email.as_string()
)
print(email.as_string())
import random
import requests
def send_message_by_luosimao(tel, message):
"""发送短信"""
resp = requests.post(
url='http://sms-api.luosimao.com/v1/send.json',
auth=('api','f2ecf586f7e3a6822f6144de9a810fc2'),
data={
'mobile':tel,
'message':message
},
timeout=10,
verify=False
)
return resp.json()
def gen_mobile_code(length=6):
return ''.join(random.choices('0123456abcde'))
code = gen_mobile_code()
message = f'验证码是{code} 哈哈哈哈'
print(send_message_by_luosimao('15533946558', message))