python 调用smtplib 发送邮件问题(Python 增加starttls(), Perl中增加doSSL 参数)

编程入门 行业动态 更新时间:2024-10-15 16:24:35

python 调用smtplib <a href=https://www.elefans.com/category/jswz/34/1770428.html style=发送邮件问题(Python 增加starttls(), Perl中增加doSSL 参数)"/>

python 调用smtplib 发送邮件问题(Python 增加starttls(), Perl中增加doSSL 参数)


最近公司切换网络采用新的邮件服务器后,Python不能调用新的服务器发送邮件,报以下错误。
(PS 邮件服务器的地址要管理员在office365上用MX 方式生成新的服务器地址供python调用)
报错一:
smtplib.SMTPRecipientsRefused: 

{'xx.xx@arraycomm': (550, b'5.7.606 Access denied, banned sending IP [xx.150.46.xx]. To request removal from this list please visit / and follow the directions. For more information please go to  /?LinkID=526655 AS(1430) [SHAFFO30FD005.protectioncn.gbl]'), 

'xx.xx@arraycomm': (550, b'5.7.606 Access denied, banned sending IP [xx.150.46.xx]. To request removal from this list please visit / and follow the directions. For more information please go to  /?LinkID=526655 AS(1430) [SHAFFO30FD005.protectioncn.gbl]')}

报错二:
  File "C:\Python36\lib\smtplib.py", line 387, in getreply
    line = self.file.readline(_MAXLINE + 1)
  File "C:\Python36\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

在python代码中原来的code:
self.smtpObj.sendmail(self.sender, toUsers, message.as_string())

改成以下,可以收到邮件:
self.smtpObj.ehlo()
self.smtpObj.starttls()
self.smtpObj.sendmail(self.sender, toUsers, message.as_string())

再改成也可以收到邮件:
self.smtpObj.starttls()
self.smtpObj.sendmail(self.sender, toUsers, message.as_string())

 

查看了下加的函数:

    def starttls(self, keyfile=None, certfile=None, context=None):
        """Puts the connection to the SMTP server into TLS mode.

        If there has been no previous EHLO or HELO command this session, this
        method tries ESMTP EHLO first.

        If the server supports TLS, this will encrypt the rest of the SMTP
        session. If you provide the keyfile and certfile parameters,
        the identity of the SMTP server and client can be checked. This,
        however, depends on whether the socket module really checks the
        certificates.

        This method may raise the following exceptions:

         SMTPHeloError            The server didn't reply properly to
                                  the helo greeting.

 

同时如果Perl中也出现这个问题,解决方法:

改用Net::SMTPS 模块,在new方法中增加doSSL 参数。亲测有效。

更多推荐

python 调用smtplib 发送邮件问题(Python 增加starttls(), Perl中增加doSSL 参数)

本文发布于:2024-02-06 15:37:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1750142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送邮件   参数   smtplib   python   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!