发送丰富电子邮件的Python包。
concrete-mailer的Python项目详细描述
自述文件
代码质量
说明
concrete-mailer
是一个用于发送丰富电子邮件的python包。在
- 它会自动将链接图像嵌入电子邮件内嵌附件中。在
- 它避免了电子邮件最终成为垃圾邮件(应用最佳实践,没有保证)
- 它自动将纯文本格式的富电子邮件转换为未启用HTML格式的接收者
- 它允许发送带有附件的电子邮件
- 它包含CSS(HTML电子邮件中没有标题)
在⚠ warning它需要一个SMTP服务器。在
设置环境
pip install concrete-mailer
用户指南
concrete-mailer
有两种用法:
1-电子邮件客户端(客户端.py)
^{pr2}$send
方法返回:
True
如果电子邮件发送成功。在False
如果出现问题。在
2-电子邮件编制者(制单人.py)
fromconcrete_mailer.preparersimportprepare_emailimportos#: Define the smtp connexion variables in:#: SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_HOST_USER, SMTP_HOST_PASSWORDforname,emailin(('John','john@mail.ext'),('Jane','jane@mail.ext')):email=prepare_email(context={'name':name},html=''' <h1>Concrete Mailer</h1> <p>Hello {{name}}. Welcome to README</p> <img src="/path/to/image1.jpg"> ''',title='README',css='',#: extra csssender='Netsach <sender@netsach.org>',reply_to='contact@netsach.org',recipients=[email,'cc@netsach.org'],attachments=['/path/to/file.zip','/path/to/image2.png'],email_host=os.getenv('SMTP_HOST_NAME'),#: smtp hostnameemail_port=os.getenv('SMTP_HOST_PORT'),#: smtp host portemail_host_user=os.getenv('SMTP_HOST_USER'),#: smtp host usernameemail_host_password=os.getenv('SMTP_HOST_PASSWORD'),#: smtp host passworduse_tls=os.getenv('SMTP_USE_TLS')=='1',#: smtp use tls)email.send()
send
方法返回:
True
如果电子邮件发送成功。在False
如果出现问题。在
调试
Python标准包包含一个smtpd
模块。在
This module offers several classes to implement SMTP (email) servers.
其中一个类是DebuggingServer
。在
Create a new debugging server. Arguments are as per SMTPServer. Messages will be discarded, and printed on stdout.
如果要测试电子邮件,请打开新控制台并调用以下命令:
python3 -m smtpd -n -c DebuggingServer localhost:1025
并配置您的环境:
SMTP_HOST_NAME='localhost'SMTP_HOST_PORT='1025'SMTP_HOST_USER=''SMTP_HOST_PASSWORD=''SMTP_USE_TLS=''
邮件正文将显示在控制台中,而不是发送到目的地。仅建立本地stmp连接(试运行)
- 项目
标签: