提交 11d9364b 编写于 作者: 东方怂天's avatar 东方怂天

Initial commit

上级
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (2)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/邮件发送.iml" filepath="$PROJECT_DIR$/.idea/邮件发送.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
# 第三方 SMTP 服务
mail_host="smtp.qq.com" #设置服务器
mail_user="849919718@qq.com" #用户名
mail_pass="qgazsthdfsaybedi" #口令
sender = '849919718@qq.com'
receivers = ['849919718@qq.com'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
#创建一个带附件的实例
message = MIMEMultipart()
message['From'] = Header("菜鸟教程", 'utf-8')
message['To'] = Header("测试", 'utf-8')
subject = 'Python SMTP 邮件测试'
message['Subject'] = Header(subject, 'utf-8')
#邮件正文内容
message.attach(MIMEText('这是菜鸟教程Python 邮件发送测试……', 'plain', 'utf-8'))
# 构造附件1,传送当前目录下的 test.txt 文件
att1 = MIMEText(open('test.txt', 'rb').read(), 'base64', 'utf-8')
att1["Content-Type"] = 'application/octet-stream'
# 这里的filename可以任意写,写什么名字,邮件中显示什么名字
att1["Content-Disposition"] = 'attachment; filename="test.txt"'
message.attach(att1)
# 构造附件2,传送当前目录下的 runoob.txt 文件
att2 = MIMEText(open('runoob.txt', 'rb').read(), 'base64', 'utf-8')
att2["Content-Type"] = 'application/octet-stream'
att2["Content-Disposition"] = 'attachment; filename="runoob.txt"'
message.attach(att2)
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message.as_string())
print("邮件发送成功")
except smtplib.SMTPException:
print("Error: 无法发送邮件")
\ No newline at end of file
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import yagmail
# 链接邮箱服务器
username = "849919718@qq.com"
passwd = "qgazsthdfsaybedi"
mail = yagmail.SMTP(user=username,
password=passwd,
host='smtp.qq.com', # 其他服务器就smtp.qq.com smtp.126.com
smtp_ssl=True
) # 如果用的是qq邮箱或者你们公司的邮箱使用是安全协议的话,必须写上 smtp_ssl=True
mail.send(
to=['849919718@qq.com', '3021921315@qq.com'], # 如果多个收件人的话,写成list就行了,如果只是一个账号,就直接写字符串就行to='12345678@qq.com'
cc='849919718@qq.com', # 抄送
subject='学习发送邮件', # 邮件标题
contents='你好,你今天开心吗?', # 邮件正文
attachments=[r'C:\Users\asus\Desktop\BK3 U1A要点总结.docx',
r'C:\Users\asus\Desktop\1825101045 杨祉 报告1.doc']) # 附件如果只有一个的话,用字符串就行,attachments=r'C:\\pp\\b.txt'
print('发送成功')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册