有什么方法可以使用 Django 的 send_mail() 函数发送附件吗?
如果没有,有人可以给我发送一个链接到具有这种可能性的模块。
是的,你可以:
from django.core.mail.message import EmailMessage
email = EmailMessage()
email.subject = "New shirt submitted"
email.body = html_message
email.from_email = "ThatAwesomeShirt! <[email protected]>"
email.to = [ "[email protected]", ] <p></p>
# Attach a file directly
email.attach_file("img.jpg")
# Or alternatively, if you want to attach the contents directly
file = open("img.jpg", "rb")
email.attach(filename = "hellokitty.jpg", mimetype = "image/jpeg", content = file.read())
file.close()
email.send()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句