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

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

        通过 SMTP Python 发送电子邮件时遇到问题

        时间:2023-07-03
        <tfoot id='55QTQ'></tfoot>

          <legend id='55QTQ'><style id='55QTQ'><dir id='55QTQ'><q id='55QTQ'></q></dir></style></legend>
          <i id='55QTQ'><tr id='55QTQ'><dt id='55QTQ'><q id='55QTQ'><span id='55QTQ'><b id='55QTQ'><form id='55QTQ'><ins id='55QTQ'></ins><ul id='55QTQ'></ul><sub id='55QTQ'></sub></form><legend id='55QTQ'></legend><bdo id='55QTQ'><pre id='55QTQ'><center id='55QTQ'></center></pre></bdo></b><th id='55QTQ'></th></span></q></dt></tr></i><div id='55QTQ'><tfoot id='55QTQ'></tfoot><dl id='55QTQ'><fieldset id='55QTQ'></fieldset></dl></div>
            <bdo id='55QTQ'></bdo><ul id='55QTQ'></ul>
            • <small id='55QTQ'></small><noframes id='55QTQ'>

                <tbody id='55QTQ'></tbody>

                1. 本文介绍了通过 SMTP Python 发送电子邮件时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  因此,我尝试使用 Python 通过 SMTPlib 发送电子邮件,但无法正常工作.我阅读了 Microsoft SMTP 规范,并相应地将它们放入其中,但我无法让它工作.这是我的代码:

                  So I'm trying to send an email through SMTPlib with Python, but I can't get it to work. I read up on the Microsoft SMTP specs, and put them in accordingly, but I can't get it to work. Here is my code:

                      # Send an email
                      SERVER  = "smtp-mail.outlook.com"
                      PORT    = 587
                      USER    = "******@outlook.com"
                      PASS    = "myPassWouldBeHere"
                      FROM    = USER
                      TO      = ["******@gmail.com"]
                      SUBJECT = "Test"
                      MESSAGE = "Test"
                      message = """
                  From: %s
                  To: %s
                  Subject: %s
                  %s
                  """ % (FROM, ", ".join(TO), SUBJECT, MESSAGE)
                      try:
                          server = smtplib.SMTP()
                          server.connect(SERVER, PORT)
                          server.starttls()
                          server.login(USER,PASS)
                          server.sendmail(FROM, TO, message)
                          server.quit()
                      except Exception as e:
                          print e
                          print "
                  Couldn't connect."
                  

                  我从键盘记录器中获得了代码,但我对其进行了一些清理.我阅读了 here 了解基本 SMTP 的工作原理,但很少有像 这样的东西starttls(方法)我不太明白.

                  I got the code from a keylogger, but I cleaned it up a bit. I read up here on how basic SMTP works, but there are few things like starttls (Methods) I don't quite understand.

                  非常感谢您对此提供的任何帮助.

                  I really appreciate any help with this.

                  推荐答案

                  试试这个.这适用于 Python 2.7.

                  Try this. This works in Python 2.7.

                  def send_mail(recipient, subject, message):
                  
                      import smtplib
                      from email.MIMEMultipart import MIMEMultipart
                      from email.MIMEText import MIMEText
                  
                      username = "sender@outlook.com"
                      password = "sender's password"
                  
                      msg = MIMEMultipart()
                      msg['From'] = username
                      msg['To'] = recipient
                      msg['Subject'] = subject
                      msg.attach(MIMEText(message))
                  
                      try:
                          print('sending mail to ' + recipient + ' on ' + subject)
                  
                          mailServer = smtplib.SMTP('smtp-mail.outlook.com', 587)
                          mailServer.ehlo()
                          mailServer.starttls()
                          mailServer.ehlo()
                          mailServer.login(username, password)
                          mailServer.sendmail(username, recipient, msg.as_string())
                          mailServer.close()
                  
                      except error as e:
                          print(str(e))
                  
                  
                  send_mail('recipient@example.com', 'Sent using Python', 'May the force be with you.')
                  

                  这篇关于通过 SMTP Python 发送电子邮件时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 Python 连接到 SMTP(SSL 或 TLS) 下一篇:通过 smtplib 发送电子邮件时如何在电子邮件内容中添加 href 链接

                  相关文章

                  • <bdo id='IxKsC'></bdo><ul id='IxKsC'></ul>

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

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

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