Reputation: 1496
I am currently porting code for a service from using SMTP to Office 365.
With SMTP I am able to set different user names on a mail from shared inbox using the "from" field, while retaining the shared email box address. This does not appear to be working via Office 365.
The process flow is:
Using the Microsoft.Graph API I can send / receive emails, but I can't spoof the user's name on to the outgoing email from the shared box, it always shows (to the recipient) as the name of the shared box.
Here is the code:
try
{
var sendMessage = new Message()
{
ToRecipients = new List<Recipient> { new Recipient()
{
EmailAddress = new EmailAddress()
{
Address = "[email protected]"
}
}
},
From = new Recipient()
{
EmailAddress = new EmailAddress()
{
Address = "[email protected]",
Name = "ALLOCATED USER NAME HERE"
}
},
Subject = "Test Subject",
Body = new ItemBody()
{
ContentType = BodyType.Text,
Content = "This is a test text body"
},
Attachments = attachments
};
await Client
.Users[thisUser.Id]
.SendMail(sendMessage).Request().PostAsync();
}
catch(Exception ex)
{
Debug.WriteLine(ex);
}
Graph seems to be ignoring the recipient name altogether.
Microsoft Graph doc : Automate creating, sending and processing messages suggests
The from property can be changed if the Exchange administrator has assigned sendAs rights of the mailbox to some other users. The administrator can do this by selecting Mailbox Permissions of the mailbox owner in the Azure portal, or by using the Exchange Admin Center or a Windows PowerShell Add-ADPermission cmdlet. Then, you can programmatically set the from property to one of these users who have sendAs rights for that mailbox.
I have confirmed these permissions are set in the Office 365 portal. What else could I be missing?
Upvotes: 3
Views: 2371
Reputation: 1114
Similar problem on my end, and found an answer in the microsoft docs here: It doesn't work - it always picks the profile name matching the e-mail and uses it for the friendly name.
So in your case you would have to change the from-address also, not only the from-name.
Upvotes: 1