**I have an application to send email one user to another through Microsoft Graph API integration.*
It's working find when we send email messages contained 7-bit ASCII characters. But it insufficient for non-ASCII text encoding (such as Unicode), binary content, or attachments.*
So how can I send MIME standard data through Microsoft Graph API, Please help me out.
MIME: The SMTP protocol was originally designed to send email messages that only contained 7-bit ASCII characters. This specification makes SMTP insufficient for non-ASCII text encodings (such as Unicode), binary content, or attachments. The Multipurpose Internet Mail Extensions standard (MIME) was developed to make it possible to send many other kinds of content using SMTP.
The MIME standard works by breaking the message body into multiple parts and then specifying what is to be done with each part. For example, one part of an email message body might be plain text, while another might be HTML. In addition, MIME allows email messages to contain one or more attachments. Message recipients can view the attachments from within their email clients, or they can save the attachments.
The message header and content are separated by a blank line. Each part of the email is separated by a boundary, a string of characters that denotes the beginning and ending of each part. For more info click here
Request Body :
{
"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 : </p>
<p>! @ # $ % ^ & * ( ) _ + = - ~ ` . / * - + </p><p>0 9 8 7 6 5 4 3 2 1 </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. </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"
}
Request Header :
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", KeyConstant.USER_TOKEN);
headers.setContentType(MediaType.APPLICATION_JSON);
Request URL : KeyConstant.URL_SEND_MAIL =
Request Process :
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());
}