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

问题描述 投票:-1回答:1

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

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

所以我该如何通过Microsoft Graph API发送MIME标准数据,请帮帮我。


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

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

消息标题和内容由空白行分隔。电子邮件的每个部分都由边界(一个字符串,表示每个部分的开始和结束)分隔。有关更多信息click here


请求正文

{
  "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);

请求URL: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());
    }
spring spring-boot microsoft-graph microsoft-graph-sdks microsoft-graph-mail
1个回答
0
投票

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

更改标题配置:

HttpHeaders headers = new HttpHeaders();

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

谢谢大家

© www.soinside.com 2019 - 2024. All rights reserved.