【问题标题】:Unable to send email message on behalf of another O365 outlook account无法代表另一个 O365 Outlook 帐户发送电子邮件
【发布时间】:2019-03-04 11:16:56
【问题描述】:

由于某种原因,“代表发送”功能对我来说失败了。图表始终返回 ErrorSendAsDenied(当 FromSender 字段值不同时)。

验证帐户具有正确的配置以代表彼此发送。在花了三天多的时间后,我无法让它工作。

在身份验证期间请求以下权限:

  • openid
  • email
  • profile
  • offline_access
  • User.Read
  • Mail.Read
  • Mail.ReadWrite
  • Mail.Read.Shared
  • Mail.ReadWrite.Shared
  • Mail.Send
  • Mail.Send.Shared

对于下面的示例,用户 Gregory Test 希望代表 Sem Test 发送消息。有效的授权访问令牌(由 Gregory Test 验证)用于发送电子邮件,但电子邮件传递总是失败。

提交的 JSON 消息示例为:

{
   "Message":{
      "Subject":"Trying to send message on behalf",
      "Body":{
         "ContentType":"html",
         "Content":" email html content "
      },
      "From":{
         "EmailAddress":{
            "Address":"sem.test@contoso.com",
            "Name":"Sem Test"
         }
      },
      "Sender":{
         "EmailAddress":{
            "Address":"gregory.test@contoso.com",
            "Name":"Gregory Test"
         }
      },
      "ToRecipients":[
         {
            "EmailAddress":{
               "Address":"semtestestestes@gmail.com",
               "Name":"Sem Shehovtsov"
            }
         }
      ]
   }
}

如果SenderFrom 设置为相同的值,则工作正常。 Sender 邮箱配置为允许代表其他用户发送邮件。

有什么想法吗?

【问题讨论】:

    标签: microsoft-graph-api microsoft-graph-mail


    【解决方案1】:

    您无需设置Sender 属性,Graph 会自动为您处理。来自documentation

    为了从其他用户发送邮件,请在发送到要发送邮件的用户的电子邮件地址的邮件上设置from 属性。您无需设置 sender 属性 - Microsoft Graph 将根据授予已登录用户的邮箱权限进行适当设置。

    试试这个有效载荷:

    {
       "message":{
          "subject": "Trying to send message on behalf",
          "body":{
             "contentType":"html",
             "content":" email html content "
          },
          "toRecipients":[
             {
                "emailAddress":{
                   "address":"semtestestestes@gmail.com",
                   "name":"Sem Shehovtsov"
                }
             }
          ],
          "from":{
             "emailAddress":{
                "address":"sem.test@contoso.com",
                "name":"Sem Test"
             }
          },
       }
    }
    

    此外,您不需要同时要求 ReadReadWrite 范围。 ReadWrite 范围与 Read 范围重叠。

    【讨论】:

    • 删除“发件人”部分不会改变任何事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 1970-01-01
    • 2022-07-20
    • 1970-01-01
    • 2020-09-19
    相关资源
    最近更新 更多