Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 903869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:57:27+00:00 2026-05-15T15:57:27+00:00

I am trying to modify emails stored as text files. I first import a

  • 0

I am trying to modify emails stored as text files. I first import a message like this :

import email
f = open('filename')
msg = email.message_from_file(f)

Then, I make all the modifications I want, using the features of the email module.

The last step is to save the Message object (msg) in a file. What is the piece of code that does this ? There seems not to be any simple function like “message_to_file()”…

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:57:28+00:00Added an answer on May 15, 2026 at 3:57 pm

    The Messsage.as_string method should give you a flattened version of the message that you can write out just as you would any other string:

    msg.as_string()

    If this doesn’t provide exactly the format you want, consider trying the email.generator module? If I read things correctly, you should be able to do something like this:

    generator = email.generator.Generator(out_file)
    generator.flatten(msg)
    

    Assuming out_file is an open and writable file and msg is your message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to modify the way FOSUSerBundle validates the username/email when the user registers,
I am trying to modify a stored procedure ( adding a new column in
Im trying to modify the class below so that the scrolling text appears behind
Chip,Dirkland,DrobæSphere Inc,cdirkland@hotmail.com,usa I've been trying to use sed to modify email addresses in a
I am trying to modify this JQuery Countdown plugin to initialize itself when it
I'm trying to modify a stored procedure used in an ASP.NET page. By default,
I've copy-pasted a function that I'm trying to modify. I'd like to make it
I'm trying to modify an example in this website . I run this example
I am trying to modify a theme on wordpress. The theme shows a slider
I am trying to modify the way a category list is drawn on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.