【问题标题】:Sending mail with through python with roundcube使用roundcube通过python发送邮件
【发布时间】:2018-09-11 11:40:54
【问题描述】:

我正在尝试使用我的rouncube webmail 发送带有python 的邮件,但是当我运行它时输出此错误TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

我签入了我的邮件,我的端口是"290",它已经提供,但是当我运行该功能时,邮件没有发送。我知道如何通过turning on less secure app access 使用gmail 发送,但不知道如何使用我的webmail 发送。

我需要你的建议来解决它。

from smtplib import SMTP_SSL as SMTP
import logging, logging.handlers, sys
from email.mime.text import MIMEText



def send_message():
    text = '''
            Hello,

            Trying to send mail from my webmail in python 3. 

            Sincerely,

            My name
            '''

    message = MIMEText(text, 'plain')
    message['Subject'] = "Email Subject"
    my_email = 'joe@mycompany.com'

    # Email that you want to send a message
    message['To'] = my_email

    # You need to change here, depending on the email that you use.
    # For example, Gmail and Yahoo have different smtp. You need to know what it is.
    connection = SMTP('smtp.roundcube.com', 290)
    connection.set_debuglevel(True)

    # Attention: You can't put for example: 'your_address@email.com'.
    #            You need to put only the address. In this case, 'your_address'.
    connection.login('fred.kings', 'fredsw321a')

    try:
        # sendemail(<from address>, <to address>, <message>)
        connection.sendmail(my_email, my_email, message.as_string())
    finally:
        connection.close()



send_message()

【问题讨论】:

  • 听起来你有正确的 SMTP 服务器。我会仔细检查 smtp.roundcube.com 和 290 是服务器和端口
  • 当我这样做connection = SMTP('smtp.mycompany.com', 290)时,我仍然得到同样的错误。
  • @DaImTo 找到了有关该问题的任何答案。

标签: python smtp webmail


【解决方案1】:

我正在使用:

  • Ubuntu 18.04.4 LTS。
  • Python 3.7.4
  • Jupyter-Notebook 6.0.1
  • Anaconda 1.7.2

我可以使用 Roundcube 通过 Python 成功发送电子邮件,在 jupyter-notebook 单元格中执行以下脚本:

import smtplib

email = "myemail@mycompany.com"
password = "mypassword"
to = ["destination@dest.com"]

with smtplib.SMTP_SSL('mail.mycompany.com', 465) as smtp:

    smtp.login(email, password)

    subject = "testing mail sending"
    body = "the mail itself"

    msg = "Subject: {}\n\n{}".format(subject, body)

    smtp.sendmail(email, to, msg)

我找到了如下信息(所以你可以找到你的):

  • 登录您的公司电子邮件。
  • 查找下图并单击它(Webmail 主页)。

  • 您会看到如下内容:

  • 向下滚动,查找下图并单击它(配置邮件...)。

  • 在邮件服务器部分查找信息。

如果使用的是 465 端口(例如我的情况),则意味着您要使用 smtplib.SMTP_SSL 而不是 smtplib.SMTP。

注意:以前的代码在我的个人计算机上对我有用,但是,当我尝试在办公室的“虚拟机”上使用相同的代码时,它不起作用 strong> 工作,这让我觉得有系统限制,问题与代码无关。

希望对你有帮助,问候。

【讨论】:

    猜你喜欢
    • 2014-08-31
    • 1970-01-01
    • 2021-02-22
    • 2020-05-01
    • 2016-12-27
    • 2015-09-28
    • 2010-09-09
    • 1970-01-01
    相关资源
    最近更新 更多