发送邮件

需要开启163的smtp服务

python 发送邮件短信封装

 

 

 1 import smtplib
 2 from email.mime.text import MIMEText
 3 
 4 class MailSender():
 5 
 6     def __init__(self,sender,recever,content,password,subject="",server="smtp.163.com",port=994):
 7         """
 8 
 9         :param sender: 发送方邮箱
10         :param recever: 接收方邮箱 ,字符串存储 ','分割
11         :param content: 发送正文
12         :param password: 发送方授权码
13         :param subject: 主题可以为空
14         :param server: 邮件服务器地址
15         :param port: 邮件服务器端口
16         """
17         self.subject = subject
18         self.content = content
19         self.sender = sender
20         self.password = password
21         self.server = server
22         self.port = port
23 
24         self.message = MIMEText(content, "plain", "utf-8")
25         self.message["Subject"] = subject
26         self.message["From"] = sender
27         self.message["To"] = recever
28 
29 
30     def send(self):
31         smtp = smtplib.SMTP_SSL("smtp.163.com", 465)
32         smtp.login(sender, password)
33         try:
34             smtp.sendmail(sender, recever.split(","), self.message.as_string())
35 
36         except Exception as e:
37             print(e)
38         finally:
39             if smtp:
40                 smtp.close()
41 
42 
43 
44 
45 if __name__ == '__main__':
46     subject = "李青"
47 
48     content = """双眼失明从来不影响我"""
49 
50     sender = "1503760xxxx@163.com"
51 
52     # 解决554 DT:SPM错误,把自己的邮箱加入里面
53     recever = "1503760xxxx@163.com,2533636371@qq.com,318750798@qq.com"
54     password = "xxxx"
55 
56     mailsend = MailSender(sender=sender,recever=recever,password=password,content=content)
57     mailsend.send()
View Code

发送手机验证码

需要在https://user.ihuyi.com/index.html注册,使用APIID和APIKEY发送

python 发送邮件短信封装

 

 

相关文章:

  • 2021-11-28
  • 2022-01-12
  • 2021-07-07
  • 2021-12-24
  • 2022-02-02
  • 2021-07-18
  • 2021-06-15
  • 2021-09-15
猜你喜欢
  • 2022-01-23
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
相关资源
相似解决方案