Skip to content

Instantly share code, notes, and snippets.

@mgnisia
Created March 20, 2019 20:27
Show Gist options
  • Save mgnisia/c8efb84d730a51b64d78439b35c8ea6e to your computer and use it in GitHub Desktop.
Save mgnisia/c8efb84d730a51b64d78439b35c8ea6e to your computer and use it in GitHub Desktop.
# Creating Function to write Email as EML File to Disk
def save_message(message_admin, request, queryset):
i = 0
for message in queryset.all():
eml_content = message.get_email_object().as_bytes()
file_name = f"some_file_path/{message.subject}_{i}.eml"
print(file_name)
with open(file_name, "wb") as outfile:
outfile.write(eml_content)
i += 1
# Registering the save_message Command in the Admin panel
actions = [resend_message_received_signal, save_message]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment