Replies: 4 comments 2 replies
-
Message.to? |
Beta Was this translation helpful? Give feedback.
-
Hi janscas, Thanks for getting back to me. I did look into this earlier before headers. I think message.to only contains the mailbox recipient (non-alias) rather than the address the email was sent to. For example: for msg in filtered_messages: This will return the address of the inbox receiving the mail rather than the address it was sent to. Is there anything else I can explore within Message.to? Thanks. |
Beta Was this translation helpful? Give feedback.
-
I should also clarify that the message header as would be seen on Outlook online does contain the alias address sent to as 'To' but this is not passed on to internetmessageheaders in Graph. Thanks. |
Beta Was this translation helpful? Give feedback.
-
I was also in the same boat. I wanted to send an email to an alias of the account so that an outlook rule can detect the alias and act accordingly. Unfortunately, outlook is too smart in that it immediately resolves alias email addresses, so the sent email header looks like it was directly sent to the actual account that owned the alias. This is the way I was able to get it to work: self.account = Account(...)
...
if self.account.is_authenticated:
message = self.account.new_message(ACCOUNT_OWNER_EMAIL)
message.subject = subject
message.to.add(ACCOUNT_OWNER_ALIAS_EMAIL)
message.body_type = type
message.body = body
# https://docs.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http#request-body
data = dict(
message=message.to_api_data()
| {
"replyTo": [{"emailAddress": {"address": SOMETHING_ELSE_IF_YOU_WANT}}],
# Custom header for keeping track of alias names
# See: https://github.com/O365/python-o365/discussions/607
"internetMessageHeaders": [{"name": "X-CUSTOM-INITIAL-RECIPIENT", "value": ACCOUNT_OWNER_ALIAS_EMAIL}],
}
)
logger.warning(f"Send Email Request={pprint.pformat(data)}")
if not message.con.post(message.build_url(message._endpoints["send_mail"]), data=data):
return False
return True
return False Now the rule I have created just looks in the header of the email, and finds the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am having some trouble locating the email address a message was sent to. This becomes an issue when the email could be sent to a primary email address or an alias of that email address. All I have been able to locate so far is the primary email address within the various objects.
I have also looked at the headers but the header object does not contain 'to' as it would in the version you might see in Outlook. I found this discussion about this issue here: https://stackoverflow.com/questions/60947499/get-message-using-graph-missing-some-internetmessageheaders
Do you happen to know anywhere else I could discover the 'to' part of the message in o365 or would I need to create something custom to do this?
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions