使用roundcub通过python发送邮件

2024-06-17 15:19:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用我的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",它已经提供了,但是当我运行函数时,邮件没有发送。我知道如何用gmail发送turning on less secure app access,但不知道如何使用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()

Tags: thetofromimportyousendmessageaddress