Microsoft.Graph - Send from shared email box with different user names

不羁岁月 提交于 2021-01-28 05:18:56

问题


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:

  1. Customer fills in a web form that is sent to the shared email box
  2. 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
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!