- Прочитайте тему и содержание электронного письма в Outlook, чтобы проверить, подтвержден ли запрос. На основании этой информации действуйте следующим образом:
- Если запрос не был подтвержден, ответьте на электронное письмо с просьбой ответить.
- Если запрос подтверждено, отправьте электронное письмо с подтверждением успешного завершения операции.
Скрипт сам возвращает нормально Электронные письма "@outlook.com", но не с конкретными доменами....
Я пробовал много альтернатив для решения этой проблемы, но это кажется невозможным... Я новичок в программировании, поэтому извините за неудобства (кстати, я запускаю этот код в Jupyter/Anaconda3)
Вот мой код, показывающий мой прогресс:
import win32com.client
from datetime import datetime, timedelta
# Connect to Outlook
outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace('MAPI')
# Access the Inbox
inbox = namespace.GetDefaultFolder(6)
# Function to search for emails containing any term from the list in the body or subject
def mail_body_search(terms, folder):
term_counts = {term: 0 for term in terms} # Dictionary to store counts of each term
relevant_messages = [] # List to store relevant emails
senders = set() # Set to store unique sender emails
# Filter emails that contain any term in the body or subject
for message in folder.Items: # Iterate over items in the folder
for term in terms: # Check each term in the list
if term.lower() in message.Body.lower() or term.lower() in message.Subject.lower():
relevant_messages.append((message, message.Parent.Name)) # Add relevant email
term_counts[term] += 1 # Increment count for the found term
senders.add(message.SenderEmailAddress) # Add sender's email to the set
break # If the term is found, no need to check other terms for this email
return relevant_messages, term_counts, senders # Return the list of found emails, term counts, and unique senders
# List of terms to search
search_terms = ['Teste', 'Testing with python']
# Call the function to search for emails with any of the terms in the Inbox
results, term_counts, senders = mail_body_search(search_terms, inbox)
# Display the total number of emails found
print(f'A total of {len(results)} emails were found.')
# Display the number of emails found for each term
for term, count in term_counts.items():
print(f'{count} emails were found for "{term}".')
# Display the unique sender emails
print('Unique sender emails:')
for sender in senders:
print(sender)
Подробнее здесь: https://stackoverflow.com/questions/792 ... ail-sender
Мобильная версия