从其他用户身份发送 Outlook 邮件Send Outlook messages from another user

Exchange Online 提供的邮箱权限允许用户从其他用户身份、通讯组列表、组、资源或共享邮箱发送邮件。Exchange Online provides mailbox permissions that allow a user to send mail that appears to be sent from another user, distribution list, group, resource, or shared mailbox. Microsoft Graph 也支持此功能,但是最终结果各不相同,具体取决于在 Exchange Online 中授予的准确权限以及用于发送邮件的 API。Microsoft Graph supports this feature as well, but the end result varies depending on the exact permissions granted in Exchange Online and which API you use to send the mail.

权限Permissions

两类权限适用于从其他用户身份发送邮件:Microsoft Graph 权限和邮箱权限。Two types of permissions apply to sending messages from another user: Microsoft Graph permissions, and mailbox permissions.

Microsoft Graph 权限Microsoft Graph permissions

若要从其他用户身份发送邮件,使用用户令牌的应用程序需使用 the Mail.Send.Shared 权限。In order to send messages from another user, applications that use user tokens use the Mail.Send.Shared permission.

备注

使用应用程序令牌而不是用户令牌且已拥有管理员授予的 Mail.Send 权限的应用程序可以组织中的任何用户身份发送邮件,只需通过用户的邮箱正常发送邮件即可。Applications that use application tokens instead of user tokens and have the Mail.Send permission consented by an administrator can send mail as any user in the organization by sending the mail normally through the user's mailbox.

邮箱权限Mailbox permissions

以下两种权限会影响从其他用户身份发送邮件的最终结果:代表发送代理发送Two permissions affect the end result of sending a message from another user: Send on Behalf and Send As. 使用 Mail.Send.Shared 权限登录应用程序的用户必须至少拥有这两种权限之一,这些权限已授予从其中发送邮件的邮箱、组或通讯组列表。The user that is signed in to your application with the Mail.Send.Shared permission MUST have at least one of these permissions granted to the mailbox, group, or distribution list that the mail is from.

代表发送Send on Behalf

使用此权限时,电子邮件的收件人将在其电子邮件客户端收到此邮件是使用你的应用程序代表其他用户发送的指示。With this permission, the recipient of the email has an indication in their email client that the message was sent by the user of your application on behalf of another user.

指示邮件是由一个用户代表另一个用户发送的 Outlook 网页版屏幕截图

它在 Microsoft Graph 显示为 sender(实际发送邮件的用户)和 from(代表发送邮件的用户/组/等)属性。This is exposed in Microsoft Graph as the sender (user that actually sent the message) and from (user/group/etc. that the message appears to be from) properties.

{
  "id": "AAMkAGE1...",
  "subject": "Send mail test",
  "sender": {
    "emailAddress": {
      "name": "Adele Vance",
      "address": "AdeleV@contoso.com"
    }
  },
  "from": {
    "emailAddress": {
      "name": "Pradeep Gupta",
      "address": "PradeepG@contoso.com"
    }
  }
}

用户可以使用 Outlook 将其自己邮箱的这种权限授予其他用户。A user can grant this permission for their own mailbox to another user by using Outlook. 管理员可以在 Office 365 管理中心为任何邮箱、组或通讯组列表授予此权限。Administrators can grant this permission for any mailbox, group, or distribution list in the Office 365 admin center.

代理发送Send As

使用此权限时,不会显示邮件是以其他用户身份发送的指示。With this permission, there is no indication that the message was sent as a different user. senderfrom 属性具有相同的值。The sender and from properties have the same value.

用户无法为其邮箱授予此权限。Users cannot grant this permission to their mailboxes. 管理员可以在 Office 365 管理中心授予此权限。Admins can grant this permission in the Office 365 admin center.

通过 Microsoft Graph 发送Sending with Microsoft Graph

可以通过直接发送创建草稿然后再发送这两种方式,从其他用户身份发送邮件。You can send messages from another user by either sending directly or by creating a draft and then sending it.

如要从其他用户身份发送,请设置要从其中向用户电子邮件地址发送的邮件上的 from 属性。In order to send from another user, set the from property on the message sent to the email address of the user to send from. 无需设置 sender 属性 - Microsoft Graph 将会根据授予已登录用户的邮箱权限进行相应的设置。You don't need to set the sender property - Microsoft Graph will set it appropriately, based on the mailbox permissions granted to the user who has signed in.

例如,若要从 sales@contoso.com 组发送邮件,请按如下所示配置邮件。For example, to send mail from the sales@contoso.com group, configure the message as follows.

{
  "subject": "January sales report",
  "toRecipients": [
    {
      "emailAddress": {
        "address": "MeganB@contoso.com"
      }
    }
  ],
  "from": {
    "emailAddress": {
      "address": "sales@contoso.com"
    }
  }
}

已发送邮件行为Sent Items behavior

邮件发送完毕后,可将其保存至发送用户的“已发送邮件”文件夹、发件人用户的“已发送邮件”文件夹或两者。After the message is sent, it can be saved to the sending user's Sent Items folder, the from user's Sent Items folder, or both. 也可以完全不保存。It can also not be saved at all.

备注

如果邮件是从没有邮箱的地址(例如通讯组列表)发送,则发件人用户没有“已发送邮件”。If the message is sent from an address that does not have a mailbox (a distribution list, for example), there is no Sent Items for the from user.

  • 如果应用程序通过使用 /me 终结点(或 /users/{user-id},其中 user-id 对应于已登录的用户)发送,邮件则会默认保存至发送用户的“已发送邮件”文件夹。If your application sends by using the /me endpoint (or /users/{user-id} where the user-id corresponds to the signed in user), by default, the message will be saved in the sending user's Sent Items folder.
  • 如果应用程序通过使用 /users/{user-id}(其中 user-id 对应于已登录的用户)发送,邮件则会默认保存至发件人用户的“已发送邮件”文件夹。If your application sends by using the /users/{user-id} where the user-id corresponds to the from user, by default, the message will be saved in the from user's Sent Items folder.

    重要

    若要以此方式发送,除了代表发送代理发送权限之外,发送用户还必须具有完全访问邮箱权限。In order to send this way, the sending user must have the Full Access mailbox permission in addition to either the Send on Behalf or Send As permission.

以下其他外部因素可能会改变默认行为:The default behavior can be changed by other outside factors:

  • 管理员将发件人用户的邮箱更新为始终将从代理发送的邮件副本保存至其“已发送邮件”。Administrators can update the from user's mailbox to always save a copy of messages sent from a delegate to their Sent Items.
  • 通过在 send mail 请求中将 saveToSentItems 属性设为 false,可以防止邮件被保存至“已发送邮件”文件夹。By setting the saveToSentItems property to false in a send mail request, you can prevent the item from being saved to the Sent Items folder. 但是,如果管理员已配置“始终保存副本”设置,则邮件将被保存至发件人用户的“已发送邮件”文件夹。However, if an administrator has configured the "always save a copy" setting, the message will still be saved to the from user's Sent Items.

示例Examples

示例 1:通过 /me 终结点成功发送Example 1: Successful send through /me endpoint

在此示例中,Adele Vance 已为 Allan Deyoung 的邮箱授予代表发送权限。In this example, Adele Vance has been granted Send on Behalf permission to Allan Deyoung's mailbox.

请求Request

POST /me/sendmail
Content-Type: application/json

{
  "message": {
    "subject": "Expense reports",
    "body": {
      "contentType": "text",
      "content": "Have you submitted your expense reports yet?"
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "MeganB@contoso.com"
        }
      }
    ],
    "from": {
      "emailAddress": {
        "address": "AllanD@contoso.com"
      }
    }
  }
}

响应Response

HTTP/1.1 202 Accepted

示例 2:在无权限的情况下,尝试发送失败Example 2: Unsuccessful attempt to send without permissions

在此示例中,Adele Vance 尝试从 Patti Fernandez 身份发送电子邮件,但他并没有被授予代表发送代理发送权限。In this example, Adele Vance attempts to send an email from Patti Fernandez, but has not been granted either the Send on Behalf or Send As permission. 响应中包含 ErrorSendAsDenied 错误。The response contains a ErrorSendAsDenied error.

请求Request

POST /me/sendmail
Content-Type: application/json

{
  "message": {
    "subject": "Support ticket",
    "body": {
      "contentType": "text",
      "content": "I noticed you opened a support ticket yesterday..."
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "MeganB@contoso.com"
        }
      }
    ],
    "from": {
      "emailAddress": {
        "address": "PattiF@contoso.com"
      }
    }
  }
}

响应Response

HTTP/1.1 403 Forbidden
Content-Type: application/json

{
  "error": {
    "code": "ErrorSendAsDenied",
    "message": "The user account which was used to submit this request does not have the right to send mail on behalf of the specified sending account. Cannot submit message.",
    "innerError": {
      "request-id": "24e7991e-01ae-4cc2-8e06-532a96fd8948",
      "date": "2019-01-16T18:53:25"
    }
  }
}

后续步骤Next steps

详细了解以下信息:Find out more about: