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

Spring Microsoft Graph API不支持发送电子邮件(POST请求)的MIME(多用途Internet邮件扩展)标准,spring,spring-boot,microsoft-graph-api,microsoft-graph-sdks,microsoft-graph-mail,Spring,Spring Boot,Microsoft Graph Api,Microsoft Graph Sdks,Microsoft Graph Mail,**我有一个应用程序,可以通过Microsoft Graph API集成向一个用户发送电子邮件* 当我们发送包含7位ASCII字符的电子邮件时,它会起作用。但它不足以用于非ASCII文本编码(如Unicode)、二进制内容或附件* 那么如何通过Microsoft Graph API发送MIME标准数据,请帮助我。 MIME:SMTP协议最初设计用于发送仅包含7位ASCII字符的电子邮件。此规范使SMTP不足以用于非ASCII文本编码(如Unicode)、二进制内容或附件。开发多用途Intern

**我有一个应用程序,可以通过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": "rajibgarai@gamail.com"
        }
      }
    ]
  },
  "saveToSentItems": "true"
}
HttpHeaders headers = new HttpHeaders();

headers.add("Authorization",  KeyConstant.USER_TOKEN);  
headers.setContentType(MediaType.APPLICATION_JSON);
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());
    }
请求URL:KeyConstant.URL\u发送\u邮件=

请求过程

{
  "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": "rajibgarai@gamail.com"
        }
      }
    ]
  },
  "saveToSentItems": "true"
}
HttpHeaders headers = new HttpHeaders();

headers.add("Authorization",  KeyConstant.USER_TOKEN);  
headers.setContentType(MediaType.APPLICATION_JSON);
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());
    }
HttpEntity requestBody=新的HttpEntity(消息、头);
尝试
{
ResponseEntity result=restemplate.exchange(keycontent.URL\u SEND\u MAIL,HttpMethod.POST,requestBody,String.class);
}
catch(org.springframework.web.client.httpclienterre)
{
错误(“发送电子邮件时发生异常:{}{}”,e.getCause(),e.getMessage());
}
捕获(例外e)
{
log.error(“发送电子邮件{}{}时发生异常”,e.getCause(),e.getMessage());
}

我发现了一个解决方案,通过对代码进行以下更改,可以支持Microsoft Graph API中所有类型的特殊字符()

更改标头配置:

HttpHeaders headers = new HttpHeaders();

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

更多信息: