SMTP 및 IMAP 프로토콜은 두 가지로 구분됩니다. : SMTP 서버를 통해 보낸 메일은 IMAP에서 볼 수 없습니다.
따라서 자신의 주소로 메일을 보내고 (MIME 개체의 "받는 사람 :"헤더에 추가하지 않고)이 동작을 직접 시뮬레이션 한 다음 올바른 상자에 메일을 이동하십시오.
def send(self, recipients, mime_message):
"""
From the MIME message (object from standard Python lib), we extract
information to know to who send the mail and then send it using the
SMTP server.
Recipients list must be passed, since it includes BCC recipients
that should not be included in mime_message header.
"""
self.smtp_connection.sendmail(
self.email_account,
recipients + [self.email_account],
mime_message.as_string()
)
### On the IMAP connection, we need to move the mail in the "SENT" box
# you may need to be smarter there, since this name may change
sentbox_name = 'Sent'
# 1. Get the mail just sent in the INBOX
self.imap_connection.select_folder('INBOX', readonly=False)
sent_msg_id = self.imap_connection.search(['UNSEEN', 'FROM', self.username])
if sent_msg_id:
# 2. Mark it as read, to not bother the user at each mail
self.imap_connection.set_flags(sent_msg_id, '\Seen')
# 3. Copy the mail in the sent box
self.imap_connection.copy(sent_msg_id, sentbox_name)
# 4. Mark the original to delete and clean the INBOX
self.imap_connection.set_flags(sent_msg_id, '\Deleted')
self.imap_connection.expunge()
: 이름
smtp_connection
및
imap_connection
올바르게 동일한 계정으로, 초기화 API를 추상화,
self.email_account
를 사용