问题
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:
- Customer fills in a web form that is sent to the shared email box
- The service reads the email, allocates a user to this inquiry and sends a confirmation email back to the customer from the shared box but with the user's name
- Any reply from the customer comes back to the shared box for further processing
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 = "customer@customer-domain.com"
}
}
},
From = new Recipient()
{
EmailAddress = new EmailAddress()
{
Address = "shared-box@my-domain.com",
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?
来源:https://stackoverflow.com/questions/64891817/microsoft-graph-send-from-shared-email-box-with-different-user-names