使用方式
发布地址:
github地址 https://github.com/majormj/snemail
gitee 地址 https://gitee.com/manjim/snemail
测试环境
目前测试支持的python版本3.6,和python 3.11 如果登录失败遇到错误 con 不存在,可尝试修改python版本的判断范围尝试(ssl的校验方式)
def mail_login(self,user="",password=""):
"""登录邮箱"""
self.emailCome = user # 邮件的时间发送人(发邮件的时候调用)
self.loginStatus = False # 登录结果状态
try:
# 1、链接邮箱服务器(带 SSL 启用安全机制) # 端口号:465/25
# 1.1 判断python版本
vamax = sys.version_info.major # 大版本号例如3.6.8 则表示3
vsmin = sys.version_info.minor # 小版本号例如3.6.8 则表示6
if vamax == 3 and vsmin < 10: # python 版本号等于3,小版本号小于10
self.con = smtplib.SMTP_SSL(self.server,self.port)
else:
""" Python 3.10 及以上版本使用"""
import ssl
ctx = ssl.create_default_context()
ctx.set_ciphers('DEFAULT')
self.con = smtplib.SMTP_SSL(self.server,port=self.port, context = ctx)
# 2、登录邮箱 # 链接对象.login(账号、密码)
self.con.login(user,password)
self.loginStatus = True
return '邮箱登录成功'
except SMTPAuthenticationError as e:
return '登录失败,请检查账户密码是否正确,或者尝试授权码登录%s'%repr(e)
except Exception as error:
return '邮箱登录遇到错误:%s'%repr(error)
依赖说明
包依赖 smtplib 模块,和 email 模块,这两个库在python11中是标准库。如果在其他python中不存在折两个库 直接 pip install smtplib 可能安装失败,可以试下安装 PyEmail,但是这个没试过不确定能不能用
pip install PyEmail
安装包
# 安装库到最新版本
pip install --upgrade snemail
使用方式
# 引入包
from snemail import SnEmail
# 邮件服务器
server = 'smtp.sina.net'
# 邮件端口
port = 465
if __name__ == '__main__':
# 初始化
sn = SnEmail(server,port)
# 设置邮件主题
sn.mail_title(title="测试邮件")
# 设置邮件正文内容,支持 文本 和thml格式 ,
"""
添加邮件内容 参数说明
content : 邮件内容
ctype : 邮件类型 plain 文本类型;html 为HTML类型;base64(二进制文件,也就是附件)
encode : 编码方式,默认 'utf-8'
"""
sn.mail_content("文本内容1")
sn.mail_content("文本内容2")
# 将图片以内容形式添加到邮件正文,图片地址字符串类型
sn.mail_image(image_path="图片地址1")
sn.mail_image(image_path="图片地址2")
# 添加邮件附件(中英文文件名都支持),传入参数 files 必须是列表
sn.mail_file([r"C:\Users\manji\Downloads\全量商品列表.xlsx"])
# 登录邮箱
print(sn.login(user="",password=""))
# 发送邮件,扩展参数可查看函数提示
"""
发送邮件
emailTo 收件人列表
emailCC 抄送人列表
emailNoSend 不发送的对象(会显示,实际不发送)
emailComeShow 显示的发件人(和实际发件人可能不是同一个)
"""
print(sn.mail_send(emailTo=['']))
Metadata
Release files for snemail 1.1.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| snemail-1.1.16.tar.gz | 6.2 kB | Without provenance | Details for snemail-1.1.16.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| snemail-1.1.16-py3-none-any.whl | Python 3 | none | any | Details for snemail-1.1.16-py3-none-any.whl |
Total release size: 13.3 kB
Release files / snemail-1.1.16.tar.gz
| Download URL | snemail-1.1.16.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0bc4ca78267f0d821b4408215d2be3ee7bb8133854f44aac39bab76561bbd9a6
|
|
BLAKE2b-256 checksum How to use checksums |
207a6abd81b6cd770554acef5939540922548a53bbcb62d9d0a5603a4d6ddc8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / snemail-1.1.16-py3-none-any.whl
| Download URL | snemail-1.1.16-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c9347dd58d18509f7760a247ea17b1c51002e61747b01c63a7bc15e10af99a9a
|
|
BLAKE2b-256 checksum How to use checksums |
c9d81c557979f61ff282a7be3e907b054fc0e210fd9fdf20d429bcd98c9d239c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Security for snemail 1.1.16
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.