yagmail
yagmail copied to clipboard
Can sending attachments be a file stream? Don't want absolute paths, reduce file generation and deletion
发送附件可以是文件流吗? 不想要绝对路径,减少文件的生成与删除
It actually already works!
import yagmail
yag = yagmail.SMTP(username, password)
with open("data.parquet.snappy", "rb") as f:
yag.send(attachments=f)
or even:
import yagmail
with yagmail.SMTP(user, pw) as yag, open("data.parquet.snappy", "rb") as f:
yag.send(attachments=f)
It actually already works!
import yagmail yag = yagmail.SMTP(username, password) with open("data.parquet.snappy", "rb") as f: yag.send(attachments=f)
or even:
import yagmail with yagmail.SMTP(user, pw) as yag, open("data.parquet.snappy", "rb") as f: yag.send(attachments=f)
open method return a io.BufferedReader object, but how can i send attachments like a io.BytesIO object?
use StringIO as an example:
from io import StringIO
import yagmail
buffer = StringIO("some string")
buffer.name = 'file.txt'
yag = yagmail.SMTP(username, password)
yag.send(attachments=buffer)
Thanks @flatflax! Closing as I think it has been answered