Jump to content
  • Sign Up
Sign in to follow this  

Salvar arquivo txt em Python

Recommended Posts

Boa tarde,


Tenho um script em python que ele se conecta em uma conta IMAP e baixa os e-mails e salva em um txt, porem está salvando apenas um ultimo e-mail, fiz um teste com o print e ele lê todos os e-mails, porem na hora de salvar ele salva o último e-mail, ele simplesmente sobrescreve o conteúdo do arquivo, independente do atributo que coloco para abrir o arquivo.


Veja como está o script

import imaplib, datetime

data_local	="%d-%m-%Y - %H.%M")
dominio		=	("***********")
porta		=	143
usuario		=	"************"	
senha		=	"************"

mail = imaplib.IMAP4(dominio, porta)
mail.login(usuario, senha)'INBOX')
#Search for all UIDs first
result, data = mail.uid('search', None, 'ALL')
uids = data[0].split()
#Loop through each uid to fetch headers
for uid in uids:
    result, data = mail.uid('fetch',uid, '(RFC822)')
	#Headers will be stored here which can then be saved in a text file
    print data[0][1]

file = open('exemplos/log/' + dominio + '_' + data_local+'.txt', 'a')

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...