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 6867397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:18:16+00:00 2026-05-27T03:18:16+00:00

I want to write a python module that sends data to a draft message

  • 0

I want to write a python module that sends data to a draft message in a G-mail account. I have written a script about two weeks ago that worked perfectly using imaplib. A simplified example of my module is below. (I have created a test email address for anyone to test this script on.)

import imaplib
import time
conn = imaplib.IMAP4_SSL('imap.gmail.com', port = 993)
conn.login('testpythoncreatedraft@gmail.com', '123456aaa')
conn.select('[Gmail]/Drafts')
conn.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), "TEST")

It utilized the .append function, but today when I run the module and it produces the following error:

Traceback (most recent call last):
  File "C:/Windows/System32/email_append_test.py", line 6, in <module>
    conn.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), "TEST")
  File "C:\Python26\lib\imaplib.py", line 317, in append
    return self._simple_command(name, mailbox, flags, date_time)
  File "C:\Python26\lib\imaplib.py", line 1060, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "C:\Python26\lib\imaplib.py", line 895, in _command_complete
    raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: APPEND command error: BAD ['Invalid Command']

As I said before, this module worked before. It successfully created draft messages with the string “Test” in its body. Since this script used to work, it seems more likely that it has something to do with a change Google made to the G-mail accounts IMAP features, but the error seems to indicate an error in the APPEND command. I have tested the python script on two different computer to see if my library file was corrupt, but the same error remained.

Also, I am using Python 2.6. Any help is appreciated.

  • 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-27T03:18:17+00:00Added an answer on May 27, 2026 at 3:18 am

    Before the conn.append, add the following:

    import email
    

    Then change the conn.append line to read:

    conn.append("[Gmail]/Drafts",
                '',
                imaplib.Time2Internaldate(time.time()),
                str(email.message_from_string('TEST')))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a program that sends an e-mail to one or more
I want to write a Python script that runs another program, reading the output
As part of some WSGI middleware I want to write a python class that
I want to write a function in Python that returns different fixed values based
I have a Python list, say l = [1,5,8] I want to write a
I want to write a Python program that makes PNG files. My big problem
I want to write a server that can accept multiple clients in python (twisted).
I have a Python function that writes an output file to disk. I want
I'm using Python's built-in unittest module and I want to write a few tests
In Python I want to call a script that prints to the screen as

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.