Attach generated CSV file to email and send with Django

前端 未结 3 1018
盖世英雄少女心
盖世英雄少女心 2021-02-04 00:54

I need to generate a csv file based on the queryset result, attach the resulting file to an email as attachment and send. As you can see i need to iterate over the assigned_lead

3条回答
  •  無奈伤痛
    2021-02-04 00:57

    Neither are working :(
    
    Approach 1:
            msg = EmailMultiAlternatives(subject, body, from_email, [to])
            msg.attach_alternative(file_content, "text/html")
            msg.content_subtype = 'html'
            msg.send()
    
    Approach 2: 
            # email = EmailMessage(
            #     'Report Subject',
            #     "body",
            #     'xx@yy.com',
            #     ['zz@uu.com'],
            #     connection=connection,
            # )
            # email.attach('Report.html', body, 'text/html')
            # email.send()
    

提交回复
热议问题