python 邮件模块yagmail官方文档翻译(部分)

最近在研究python的邮件模块yagmail,顺手把官方文档翻译一下,希望能帮到一些需要的人。
原:
You can send an E-Mail to a single user by simply passing a string with either a GMail username (@gmail.com will be appended automatically), or with a full E-Mail address:
译:
你可以只用GMail邮箱的用户名给单个用户发邮件(邮箱后缀@gmail.com会自动补充),当然你用完整的邮箱地址发邮件。
注:自动补全应该只对GMail邮箱有效,有兴趣的可以验证一下。

yag.send(to='mike@gmail.com', contents="Hello, Mike!")

原:
Alternatively, you can send E-Mails to a group of people by either passing a list or a tuple of E-Mail addresses as to:
译:
或者,你可以用邮箱地址列表或元组来给一组人发邮件,方法如下:
邮箱列表

yag.send(to=['to@someone.com', 'for@someone.com'], contents="Hello there!")

邮箱元组:

yag.send(to='to@someone.com', 'for@someone.com', contents="Hello there!")

原:
These E-Mail addresses were passed without any aliases. If you wish to use aliases for the E-Mail addresses, provide a dictionary mapped in the form {address: alias}, for example:
译:
邮箱地址可以不适用别名,如果你想给邮箱地址加个别名,可以用字典格式来存放{address:alias},比如:

recipients = {
    'aliased@mike.com': 'Mike',
    'aliased@fred.com': 'Fred'
}
yag.send(to=recipients, contents="Hello, Mike and Fred!")

Magical contents(多种多样的邮件内容)
原:
The contents argument of yagmail.SMTP.send() will be smartly guessed. You can pass it a string with your contents or a list of elements which are either:

If it is a dictionary, then it will be assumed that the key is the content and the value is an alias (currently, this only applies to images). For example:
译:
发送的邮件内容能被智能的识别出来,你的邮件内容可以是字符串,也可以是列表,如果是字典,其key会被识别为内容,其value会被识别为别名(目前,这种方法仅限于图片附件)。例如:

contents = [
    "Hello Mike! Here is a picture I took last week:",
    {'path/to/my/image.png': 'PictureForMike'}
]

原:
If it is a string, then it will first check whether the content of the string can be read as a file locally, for example ‘path/to/my/image.png’. These files require an extension for their content type to be inferred.
If it could not be read locally, then it checks whether the string is valid HTML, such as

This is a big title!

.
If it was not valid HTML either, then it must be text, such as “Hello, Mike!”.
If you want to ensure that a string is treated as text and should not be checked for any other content as described above, you can use yagmail.raw, a subclass of str.

If you intend to inline an image instead of attaching it, you can use yagmail.inline.
译:
如果内容是是字符串,它首先会被检测是否是本地文件,比如:‘path/to/my/image.png’。这些文件需要有扩展名。
如果内容字符串内容不是本地文件,接着会被检测是否是有效的html文本,如:

This is a big title!


如果也不是有效的HTML文本,那么它应该就是文本了,如:“Hello, Mike!”
如果你想确保字符串不被识别为以上的其他内容,你可以用yagmail.raw(str)方法,字符串子类。
如果你只是想把图片放在正文中而不是作为附件,你可以用yagmail.inline(str)方法。

yagmail官方文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值