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

  • <legend id='xe5DZ'><style id='xe5DZ'><dir id='xe5DZ'><q id='xe5DZ'></q></dir></style></legend>

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

        • <bdo id='xe5DZ'></bdo><ul id='xe5DZ'></ul>
        <tfoot id='xe5DZ'></tfoot>

        使用 python 从 gmail 下载 csv 文件

        时间:2023-10-20

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

        1. <tfoot id='Z65Aq'></tfoot>

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

                    <tbody id='Z65Aq'></tbody>
                  本文介绍了使用 python 从 gmail 下载 csv 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试了不同的 python 脚本来从 Gmail 下载 CSV 附件.但我无法得到它.这可能吗.如果有可能我应该使用哪个 python 脚本?谢谢.

                  I tried different python scripts for download a CSV attachment from Gmail. But I could not able to get it.Is this possible. If it is possible which python script should I use? Thank you.

                  推荐答案

                  我明白了.这不是我自己的工作.我得到了一些代码,将它们组合起来并修改为这段代码.但是,最终,它奏效了.

                  I got it. This is not my own work. I got some codes, combined them and modified to this code. However, finally, it worked.

                  print 'Proceeding'
                  
                  import email
                  import getpass
                  import imaplib
                  import os
                  import sys
                  
                  userName = 'yourgmail@gmail.com'
                  passwd = 'yourpassword'
                  directory = '/full/path/to/the/directory'
                  
                  
                  detach_dir = '.'
                  if 'DataFiles' not in os.listdir(detach_dir):
                      os.mkdir('DataFiles')
                  
                  
                  
                  try:
                      imapSession = imaplib.IMAP4_SSL('imap.gmail.com')
                      typ, accountDetails = imapSession.login(userName, passwd)
                      if typ != 'OK':
                          print 'Not able to sign in!'
                          raise
                  
                      imapSession.select('[Gmail]/All Mail')
                      typ, data = imapSession.search(None, 'ALL')
                      if typ != 'OK':
                          print 'Error searching Inbox.'
                          raise
                  
                  
                      for msgId in data[0].split():
                          typ, messageParts = imapSession.fetch(msgId, '(RFC822)')
                          if typ != 'OK':
                              print 'Error fetching mail.'
                              raise
                  
                          emailBody = messageParts[0][1]
                          mail = email.message_from_string(emailBody)
                          for part in mail.walk():
                              if part.get_content_maintype() == 'multipart':
                                  continue
                              if part.get('Content-Disposition') is None:
                                  continue
                              fileName = part.get_filename()
                  
                              if bool(fileName):
                                  filePath = os.path.join(detach_dir, 'DataFiles', fileName)
                                  if not os.path.isfile(filePath) :
                                      print fileName
                                      fp = open(filePath, 'wb')
                                      fp.write(part.get_payload(decode=True))
                                      fp.close()
                      imapSession.close()
                      imapSession.logout()
                  
                      print 'Done'
                  
                  
                  except :
                      print 'Not able to download all attachments.'
                  

                  这篇关于使用 python 从 gmail 下载 csv 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 smtplib - Python 接收来自 Gmail 的回复 下一篇:使用 Python 检查未读的 Gmail 邮件数

                  相关文章

                • <tfoot id='UK3op'></tfoot>

                  1. <small id='UK3op'></small><noframes id='UK3op'>

                    <legend id='UK3op'><style id='UK3op'><dir id='UK3op'><q id='UK3op'></q></dir></style></legend>
                    • <bdo id='UK3op'></bdo><ul id='UK3op'></ul>

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