我如何创建一个可以接收和发送邮件到 Zimbra 服务器的模块

How I can create a module which can receive and send mails to Zimbra server

我如何创建一个模块来接收和发送邮件(过滤垃圾邮件)到 Zimbra 服务器,这是完成此任务的最佳程序语言?

此代码将发送一封电子邮件:

import smtplib
import ssl

port = 465  # for ssl
smtp_server = 'email.com'  # if it is a gmail account, use stmp.gmail.com
sender_email = 'email@email.com'
receiver_email = 'other_email@email.com'
password = 'Password'  # sender password
subject = 'Python email test'
message = f"""From: {sender_email}
To: {receiver_email}
Subject: {subject}

This email was sent from python."""

context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
    server.login(sender_email, password)
    server.sendmail(sender_email, receiver_email, message)

此代码将读取收件箱中的第一封电子邮件:

import imaplib

server = imaplib.IMAP4_SSL('email.com', 993)  # if it is gmail use imap.gmail.com

email = 'email@email.com'
password = 'Password'

server.login(email, password)

stat, count = server.select('Inbox')  # count is the number of emails in the selected folder
                                      # in this case the Inbox
stat, data = server.fetch(count[0], 'BODY[TEXT]')  # count[0] means the first email

print(data[0][1].decode('utf-8'))