<i id='RF1jv'><tr id='RF1jv'><dt id='RF1jv'><q id='RF1jv'><span id='RF1jv'><b id='RF1jv'><form id='RF1jv'><ins id='RF1jv'></ins><ul id='RF1jv'></ul><sub id='RF1jv'></sub></form><legend id='RF1jv'></legend><bdo id='RF1jv'><pre id='RF1jv'><center id='RF1jv'></center></pre></bdo></b><th id='RF1jv'></th></span></q></dt></tr></i><div id='RF1jv'><tfoot id='RF1jv'></tfoot><dl id='RF1jv'><fieldset id='RF1jv'></fieldset></dl></div>

    <small id='RF1jv'></small><noframes id='RF1jv'>

    1. <tfoot id='RF1jv'></tfoot>
        <bdo id='RF1jv'></bdo><ul id='RF1jv'></ul>

      <legend id='RF1jv'><style id='RF1jv'><dir id='RF1jv'><q id='RF1jv'></q></dir></style></legend>
    2. 使用 python smtplib 发送邮件错误

      时间:2023-07-02

          <bdo id='O0VCc'></bdo><ul id='O0VCc'></ul>
            <tbody id='O0VCc'></tbody>
          • <legend id='O0VCc'><style id='O0VCc'><dir id='O0VCc'><q id='O0VCc'></q></dir></style></legend><tfoot id='O0VCc'></tfoot>

                <small id='O0VCc'></small><noframes id='O0VCc'>

                <i id='O0VCc'><tr id='O0VCc'><dt id='O0VCc'><q id='O0VCc'><span id='O0VCc'><b id='O0VCc'><form id='O0VCc'><ins id='O0VCc'></ins><ul id='O0VCc'></ul><sub id='O0VCc'></sub></form><legend id='O0VCc'></legend><bdo id='O0VCc'><pre id='O0VCc'><center id='O0VCc'></center></pre></bdo></b><th id='O0VCc'></th></span></q></dt></tr></i><div id='O0VCc'><tfoot id='O0VCc'></tfoot><dl id='O0VCc'><fieldset id='O0VCc'></fieldset></dl></div>
                本文介绍了使用 python smtplib 发送邮件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 python 3.2 SMTPlib.sendmail() 函数发送消息,经过 SMTP 库的一些修改(即注释掉抑制错误消息的 rset() 函数)我设法从服务器检索到以下错误消息:

                I am attempting to use the python 3.2 SMTPlib.sendmail() function to send a message, after some modifcation of the SMTP library (namely commenting out the rset() function which was suppressing the error msg) I managed to retrieve the following error message from the server:

                发送邮件失败(554, b'Transaction failed : 由于可能滥用,无法发送消息;请访问 http://postmaster.yahoo.com/abuse_smtp.html 了解更多信息')

                SendMail Failed (554, b'Transaction failed : Cannot send message due to possible abuse; please visit http://postmaster.yahoo.com/abuse_smtp.html for more information')

                雅虎邮件 SMTP 服务器认为我在发送垃圾邮件,该 URL 确实链接到任何内容有用.我认为这与标题不足有关,我似乎无法找到明确的回答什么构成合规标头和我读过 Gmail 的类似问题.此帖子已替换为模拟电子邮件.

                The yahoo mail SMTP server thinks I'm sending spam, the URL does link to anything useful. I think it has to do with an inadequate header, I can't seem to find a definitive answer on what constitutes a compliant header & I've read of simmilar issues with Gmail. Mock emails have been substituted for this post.

                任何帮助将不胜感激

                我的完整代码如下:

                    self.message =  email.message_from_string('''To: <ksmith@yahoo.co.nz>
                    From: <rwilson@yahoo.co.nz>
                    Reply-To: <rwilson@yahoo.co.nz>
                    Subject: Test send mail 
                
                 Hello''')
                    fromAddress = 'rwilson@yahoo.co.nz'
                    toAddress = 'ksmith@yahoo.co.nz'
                    try:
                        self.smtp = SMTP()
                        self.smtp.connect('smtp.mail.yahoo.com')
                    except Exception:
                        print('Connection Failed')
                        print(traceback.format_exc())
                    try:
                        self.smtp.login('rwilson','tree22')
                    except Exception:
                        print('Login Failed!')
                        print(traceback.format_exc())
                    try:
                        self.smtp.sendmail(fromAddress,toAddress ,self.message.as_string())
                        print("Message sucessfully sent!")
                        self.smtp.close()
                    except Exception as e:
                        print('SendMail Failed')
                        print(e)
                

                推荐答案

                以下适用于 Python 2.7 和 Python 3.2 上的 microsoft、google、yahoo 帐户:

                The following works for microsoft, google, yahoo accounts on Python 2.7 and Python 3.2:

                #!/usr/bin/env python
                # -*- coding: utf-8 -*-
                """Send email via smtp_host."""
                import smtplib
                from email.mime.text import MIMEText
                from email.header    import Header
                
                ####smtp_host = 'smtp.live.com'        # microsoft
                ####smtp_host = 'smtp.gmail.com'       # google
                smtp_host = 'smtp.mail.yahoo.com'  # yahoo
                login, password = ...
                recipients_emails = [login]
                
                msg = MIMEText('body…', 'plain', 'utf-8')
                msg['Subject'] = Header('subject…', 'utf-8')
                msg['From'] = login
                msg['To'] = ", ".join(recipients_emails)
                
                s = smtplib.SMTP(smtp_host, 587, timeout=10)
                s.set_debuglevel(1)
                try:
                    s.starttls()
                    s.login(login, password)
                    s.sendmail(msg['From'], recipients_emails, msg.as_string())
                finally:
                    s.quit()
                

                这篇关于使用 python smtplib 发送邮件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何使用 Python 以 Gmail 作为提供商发送电子邮件? 下一篇:如何在没有身份验证的情况下直接向 SMTP 服务器发送邮件?

                相关文章

                <i id='C0sTA'><tr id='C0sTA'><dt id='C0sTA'><q id='C0sTA'><span id='C0sTA'><b id='C0sTA'><form id='C0sTA'><ins id='C0sTA'></ins><ul id='C0sTA'></ul><sub id='C0sTA'></sub></form><legend id='C0sTA'></legend><bdo id='C0sTA'><pre id='C0sTA'><center id='C0sTA'></center></pre></bdo></b><th id='C0sTA'></th></span></q></dt></tr></i><div id='C0sTA'><tfoot id='C0sTA'></tfoot><dl id='C0sTA'><fieldset id='C0sTA'></fieldset></dl></div>

                <small id='C0sTA'></small><noframes id='C0sTA'>

              1. <legend id='C0sTA'><style id='C0sTA'><dir id='C0sTA'><q id='C0sTA'></q></dir></style></legend>

                <tfoot id='C0sTA'></tfoot>
                  <bdo id='C0sTA'></bdo><ul id='C0sTA'></ul>