为人类发送电子邮件

dlvr的Python项目详细描述


为人类发送电子邮件

安装

使用pip非常简单:

$ pip install dlvr

或者从github中签出最新版本:

$ git clone https://github.com/bmaeser/dlvr.git
$ cd dlvr
$ python setup.py install

快速启动

打开到服务器的连接:

>>> from dlvr import SMTPServer
>>> s = SMTPServer()

创建电子邮件:

>>> from dlvr import Message
>>> m = Message('bob@example.com', ['alice@gmail.com', 'support@example.com'],
        'testsubject', 'testbody')

发送电子邮件:

>>> s.connect()
>>> s.send(m)
>>> s.disconnect()

完整示例

from dlvr import SMTPServer, Message

server = SMTPServer(host="smtp.googlemail.com", port='587',
    auth_user='MYUSERNAME', auth_pass='MYPASSWOR', tls=True)

## host (optional): defaults to localhost
## port (optional): defaults to 25
## auth_user (optional): your usernamer
## auth_pass (optional): your passwort
## tls (optional): encrypt the session defaults to False

text = 'here is you link: http://www.google.com'
subject = 'the link you asked for'

html = """\
<html>
    <head></head>
    <body>
        <p>Hi!<br>
        Here is the <a href="http://www.google.com">link to google</a> you wanted.
        </p>
    </body>
</html>
"""

message = Message('bob@example.com', ['alice@gmail.com', 'support@example.com'],
    subject, text, alternatives=[(html, 'text/html')])

## constructor arguments:

## from_email: required, the senders email
## to: required, a list of recipients
## subject: required, the emails subject
## text_message (optional): the text representation of the email body
## cc (optional): a list of the carbon-copy recipients
## bcc (optional): a list of blind-carbon-copy recipients
## attachments (optional): a list of attachments, and the mimetype to use eg:
##      attachments = [('/tmp/image.jpg', 'image/jpeg'), ('/tmp/song.mp3', 'audio/mpeg3')]
## alternatives (optional): a list of alternative representation of the email body
##      and the mimetype to use
## charset (optional): the charset/encoding to use for text_message, defaults to utf-8

## message functions:

# attach_alternative(content, 'mimetype')
# where mimetype is optional und defaults to 'text/html'

# attach_file('/path/to/file', 'mimetype')
# where mimetype is opional and is guessed if not provided

server.connect()
server.send(message)
## send another message with the same open connection ...
server.disconnect()

## or shorthand if you only send one message:
server.send_email(message)

贡献

请请求并/或在github上创建问题

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
无法在Netbeans 8.2 JDK8u231中创建java Maven项目(Web应用程序)   java如何以设定的时间间隔生成随机数?   java从socket和inputStream的慢速读取   spring SCORM:Java中基于Web的SCORM播放器   Java将函数传递给方法   java绑定通用服务及其实现和子类型   java如何在运行时从选择列表框中动态选择选项?爪哇硒   java Selenium WebDriver什么是“Selenium客户端和WebDriver语言绑定”   elasticsearch需要elasticsearch高级Java客户端更新ByQueryRequest API帮助   JAVA哈希表查找最大值   WSDL操作中的java soapAction属性为空   java访问封闭类或父类方法的一般方法   eclipse在java中运行带有SeleneTestCase的ANT。lang.NoClassDefFoundError   java Hazelcast不会在节点启动时填充ReplicatedMap   如何在Java中从excel中读取特定行?   html JAVA将本地时间(GMT+8)转换为UTC时间   java将自定义端点添加到Spring数据REST存储库中,并以大摇大摆的方式显示   java计算未来位置