How to create an email and send it to a special mailbox using imaplib

I am trying to use python imaplib to create an email and send it to a mailbox with a specific name, e.g. INBOX. Someone has a great offer :).

+4
source share
4 answers

IMAP is not intended for sending emails. It is designed to manage mailboxes.

To create an email and send it, you can use SMTP, as in smtplib .

, , uid, .

+9

imaplib Python append() IMAP:

import imaplib

connection = imaplib.IMAP4_SSL(HOSTNAME)
connection.login(USERNAME, PASSWORD)

new_message = email.message.Message()
new_message["From"] = "hello@itsme.com"
new_message["Subject"] = "My new mail."
new_message.set_payload("This is my message.")

connection.append('INBOX', '', imaplib.Time2Internaldate(time.time()), str(new_message))
+6

user 3556956, python3:

connection.append('INBOX', '', imaplib.Time2Internaldate(time.time()), str(new_message).encode('utf-8'))

, Python.

0
source

I don’t know how they do it, but doesn’t Microsoft Outlook allow you to move the email from the local folder to the remote IMAP folder?

-5
source

Source: https://habr.com/ru/post/1766001/


All Articles