我在数据库中有文件的URL。我想将该文件作为附件发送到电子邮件中。我尝试了以下代码:
def mail_business_plan(sender, instance, created, **kwargs):
if created:
ctx = {"ctx":instance}
from_email = 'info@some_email.in'
subject = 'Business Plan by' + instance.company_name
message = get_template('email/business_team.html').render(ctx)
to = ['some_email@gmail.com']
mail = EmailMessage(subject, message, to=to, from_email=from_email)
mail.attach_file(instance.presentation, instance.presentation.read(), instance.presentation.content_type)
return mail.send()
我遇到了一个错误,提示为"AttributeError: 'FieldFile'对象没有'content_type'属性"
如果文件路径存储在数据库中,最佳的发送带有附件的邮件方式是什么?