I'm currently trying to automate incoming emails with python. I'm using the IMAP_TOOLS library. I've already managed to get the necessary values, but I need the time when the email response arrived, but I can't get this information
from imap_tools import MailBox, AND
from datetime import date
data_atual = date.today()
data_hoje = '{}/{}/{}'.format(data_atual.day, data_atual.month,data_atual.year)
valores_lista = []
# pegar emails de um remetente para um destinatário
username = "[REDACTED]@gmail.com"
password = "[REDACTED]"
# lista de imaps: https://www.systoolsgroup.com/imap/
meu_email = MailBox('imap.gmail.com').login(username, password)
lista = []
#pegar emails enviados por remetente especifico
coluna = 0
lista_emails = meu_email.fetch(AND(from_="[REDACTED]@gmail.com", to="c[REDACTED]@gmail.com",subject="MOV:",answered=True))
for email in lista_emails:
email_subject = email.subject
print(email_subject)
email_hora = email.date_str
#print(email_hora)
hora0, hora1, hora2, hora3, hora_enviado,hora4 = email_hora.split()
variavel0,variavel1,variavel2,variavel3,mv,variavel4 = email_subject.split()
mv_ = mv.replace("MOV:","").replace("/UP:","")
print(mv_)
#print("Envio: ",mv + hora_enviado)
#print(email.reply_to)
lista = [data_hoje,hora_enviado,"","","",mv_]
valores_lista.append(lista)
coluna += 1
print(valores_lista)
I tried to use the documentation functions from the imap_tools
documentation
msg.to_values
msg.from_values
but it returns empty.