aeliusd
aeliusd

Reputation: 469

Change the displayname of the sender when sending mail via o365?

Is it possible to control the display name of the sender when sending mails with the office 365 OutlookServicesClient? I.e., I want to use, say [email protected] as the sender which is configured with the name some [email protected] in office 365. But for a given mail I want the from name to instead be some other [email protected].

I've tried this:

Message draftMessage = new Message
{
Subject = subject,
    Body = body,
    ToRecipients = toRecip,
    CcRecipients = ccRecip,
    From = new Recipient()
    {
        EmailAddress = new EmailAddress() { Address = "[email protected]", Name = "Some other [email protected]" }
    }
};

But the mail is still sent with the preconfigured name of some [email protected].

So, is what I want possible?

Upvotes: 0

Views: 4446

Answers (1)

Joe Martella
Joe Martella

Reputation: 762

According to the reference documentation for the Message object, what you want to do is possible. However, logic tells me that shouldn't be possible, and furthermore, the testing I did showed me it wasn't possible (or isn't working). I will follow up on this and update this answer when I get a definitive answer, but at this time, it appears like you can't change the name of the sender (or it's broken).

UPDATE: The From property is writable. I've tested this using pure REST, so I can't speak exactly to what the client library you are using is doing, but I think the request is being transformed to prevent spoofing.

It is possible to control the display name of the sender, but you can only do so with other users in your Office 365 tenant. To do this, sign in to the Office 365 Admin Portal, go to Users, then Active Users, then select the user (User A) that you want to send on behalf of. Click Edit and select Mailbox Permissions. Add the alias or email address of the user (User B) who is running the code (the user authenticated with your app) to the first box under Send email from this mailbox. This will allow you to set the From property of a message sent by User B as User A.

I understand this isn't exactly what you were after, but having the ability to send email as any email address can lead to some bad stuff. Hope this helped!

Upvotes: 2

Related Questions