Gramex SMTP 电子邮件问题

Gramex SMTP Email Issue

我必须通过 python 功能向多个用户发送动态内容的电子邮件。

我在 gramex.yaml 中提供了电子邮件详细信息,如下所示

email:
  barcode-mail-service:
    type: gmail
    email: gramex.guide@gmail.com
    password: alphaBetaGamma

在我的 python 函数中,我实现了如下邮件功能:

def email_users(_pending_users, approval):
    mailer = service.email['barcode-mail-service']
    content = []
    if approval == 'Approved':
        content = [f"Hi {obj['user']},\n\n \
                    Welcome to the Service online portal!"
                    for obj in 
                    _pending_users.to_dict('r')
                  ]
    else:
        content = [f"Hi {obj['user']},\n\n \
                   Your request has been rejected by the approver!"
                   for obj in _pending_users.to_dict('r')
                  ]
    to_list = _pending_users['email'].tolist() #gets list of all email ids
    for index in range(len(to_list)): #loops over each mail id and sends the email
        mailer.mail(
            to=to_list[index],
            subject=f'Barcode User Access {approval}',
            html=content[index]
        )

当我执行上述函数时,出现以下错误:

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

我该如何解决这个问题?

这似乎是防火墙问题。 SMTP 在内部使用端口 25 发送电子邮件。在您的系统上启用(允许)端口 25 并尝试是否可行。您还需要在部署期间在服务器上启用此端口。

注意:检查您的电子邮件交换正在使用哪个端口发送电子邮件

You can check this link to enable on Windows OS