Microsoft Graph API不支持发送电子邮件(POST请求)的MIME(多用途Internet邮件扩展)标准

拉吉布·加莱(Rajib Garai):

**我有一个应用程序可以通过Microsoft Graph API集成将一个用户的电子邮件发送给另一个用户。*

当我们发送包含7位ASCII字符的电子邮件时,它是有效的。但是对于非ASCII文本编码(例如Unicode),二进制内容或附件,这是不够的。*

因此,如何通过Microsoft Graph API发送MIME标准数据,请帮帮我。


MIME:SMTP协议最初旨在发送仅包含7位ASCII字符的电子邮件。此规范使SMTP不足以用于非ASCII文本编码(例如Unicode),二进制内容或附件。开发了多用途Internet邮件扩展标准(MIME),使使用SMTP发送许多其他类型的内容成为可能。

MIME标准的工作原理是将消息正文分为多个部分,然后指定每个部分要执行的操作。例如,电子邮件正文的一部分可能是纯文本,而另一部分可能是HTML。此外,MIME允许电子邮件包含一个或多个附件。邮件收件人可以从其电子邮件客户端中查看附件,也可以保存附件。

消息标题和内容由空白行分隔。电子邮件的每个部分都由边界(一个字符串,表示每个部分的开始和结束)分隔。欲了解更多信息,请点击这里


请求正文

{
  "message": {
    "subject": "Special Mail Testing - 23652",
    "body": {
      "contentType": "html",
      "content": "<p>Hi RAJIB GARAI,</p><p>Copy Content :</p><p>In this module, you’ll learn how to manage the lifecycle of groups, the different types of groups and obtain information about the users.</p>
                    <p>Write Content :</p><p>In this module you'll learn how to manage it. Some special characters type from keybord :&nbsp;</p>
                    <p>! @ # $ % ^ &amp; * ( ) _ + = - ~ ` . / * - +&nbsp;</p><p>0 9 8 7 6 5 4 3 2 1&nbsp;</p>
                    <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.&nbsp;</p>
                    <p>The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</p>
                    <p>Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy.
                        Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
                    <p> €   ‚ ƒ „ … † ‡ ˆ ‰ Š ‹ Œ Ž ‘ ’ “ ” • – — ˜ ™ š › œ ž Ÿ ´ µ · º » ¼ û </p>"
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "[email protected]"
        }
      }
    ]
  },
  "saveToSentItems": "true"
}

请求标头

HttpHeaders headers = new HttpHeaders();

headers.add("Authorization",  KeyConstant.USER_TOKEN);  
headers.setContentType(MediaType.APPLICATION_JSON);

要求网址:KeyConstant.URL_SEND_MAIL =

https://graph.microsoft.com/v1.0/me/sendMail

申请流程

HttpEntity<String> requestBody = new HttpEntity<String>(message, headers);

    try 
    {
        ResponseEntity<String> result = restTemplate.exchange(KeyConstant.URL_SEND_MAIL, HttpMethod.POST, requestBody, String.class);

    }
    catch (org.springframework.web.client.HttpClientErrorException e)
    {
        log.error("Exception occurred while sending email : {} {}", e.getCause() ,e.getMessage());  
    }
    catch (Exception e) 
    {
        log.error("Exception occurred while sending email {} {}", e.getCause(), e.getMessage());
    }
拉吉布·加莱(Rajib Garai):

我找到了一种解决方案,该解决方案使用以下代码更改来支持Microsoft Graph API中的所有类型的特殊字符(info)。

更改标题配置:

HttpHeaders headers = new HttpHeaders();

headers.add("Authorization",  KeyConstant.USER_TOKEN); 
headers.setContentType(MediaType.APPLICATION_JSON_UTF8); // Not MediaType.APPLICATION_JSON

感谢大家

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章