O365 API, Forward an Email

465 Views Asked by At

Is there anyway to forward a message using o365 API ?

This is what i tried to far:

# Authentification
from O365 import Account, message

credentials = ('Client_ID', 'Secret_Client')
account = Account(credentials)
print(account)
if account.authenticate(scopes=['basic', 'message_all']):
   print('Authenticated!')

# Read Sent Email :
mailbox = account.mailbox()
sent_folder = mailbox.sent_folder()
for message in sent_folder.get_messages(1):
    print(message)

Is there any way how to forward that message ?

I saw that it's possible on microsoft graph using php : https://developer.microsoft.com/fr-fr/graph/graph-explorer : Check Mail : Forward Mail

Forward Microsoft Graph PHP

1

There are 1 best solutions below

0
On

You have to create a new forward() instance of the email and add data just like you would when creating a new message:

# Authentification
from O365 import Account, message

credentials = ('Client_ID', 'Secret_Client')
account = Account(credentials)
print(account)
if account.authenticate(scopes=['basic', 'message_all']):
   print('Authenticated!')

# Read Sent Email :
mailbox = account.mailbox()
sent_folder = mailbox.sent_folder()
for message in sent_folder.get_messages(1):
    # Forward email to '[email protected]' with 'Added body' above the forwarded email body:
    to_forward = message.forward()
    to_forward.to.add('[email protected]')
    to_forward.body = 'Added body'
    to_forward.send()