Search code examples
djangoemailoutlookmsgeml

How to create an eml file as outlook draft email with django EmailMessage?


I'm looking for an email as a draft. I would like to double click on later draft and send it via outlook. Currently, I am able to create the eml file and open it in outlook on double click. However, I cannot send it. Can you help me please, I spent a week above but without success.

Here is the code:

from django.core.mail import EmailMessage
@login_required
def Envoi_Mail(request):
    date_now = datetime.datetime.now().strftime("%Y-%m-%d")
    id_path = request.GET.get('id_path')
    dossier_media = str(settings.MEDIA_ROOT)
    msg = EmailMessage(
        'Bonjour',
        'Test test tes',
        '[email protected]',
        ['[email protected]'],
    )
    content_text = msg.message().as_bytes()
    file_name = dossier_media + "/" + str(date_now) + ".eml"
    with open(file_name, "wb") as outfile:
        outfile.write(content_text)
    return redirect(id_path)

Here is what I get:

enter image description here

Here is what I would like to have:

enter image description here


Solution

  • Make sure you add X-Unsent: 1 MIME header.