Answer the question
In order to leave comments, you need to log in
How to save a letter in drafts?
There is this code:
import time
import random
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import imaplib
def save_draft(email_to, body, login, password, image):
msg = MIMEMultipart("alternative")
msg.set_charset("utf-8")
msg.attach(MIMEText(body, "plain", "utf-8"))
msg['Subject'] = SUBJECT
msg['From'] = login
msg['To'] = email_to
with open(image, 'rb') as f:
part = MIMEApplication(
f.read(),
Name=image
)
part['Content-Disposition'] = 'attachment; filename={}'.format(IMAGE)
msg.attach(part)
imap = imaplib.IMAP4_SSL("imap.gmail.com", 993)
imap.login(login, password)
imap.select('[Gmail]/Drafts')
now = imaplib.Time2Internaldate(time.time())
imap.append('[Gmail]/Drafts',
'',
now,
msg.as_bytes())
imap.logout()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question