【问题标题】:How I can create a module which can receive and send mails to Zimbra server我如何创建一个可以接收和发送邮件到 Zimbra 服务器的模块
【发布时间】:2021-08-10 22:46:29
【问题描述】:

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

【问题讨论】:

  • Pyhton 之所以不错,是因为您可以发送一封电子邮件,虽然非常简单,但只需不到 20 行代码。
  • 我需要它也可以接收邮件,而不仅仅是发送电子邮件
  • 这同样适用于阅读电子邮件。你想让我用一些示例代码来回答吗?
  • 如果你能@Haveaniceday,我将不胜感激
  • 如果你愿意,我还可以展示我制作的简单电子邮件用户界面。

标签: javascript python node.js email smtp


【解决方案1】:

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

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'))

【讨论】:

    猜你喜欢
    • 2015-06-06
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    相关资源
    最近更新 更多