Как отформатировать тело письма, используя «text / plain» в качестве типа контента в wso2 EI 6.3.0? - PullRequest
0 голосов
/ 24 июня 2019

Я отправляю уведомление по электронной почте в wso2 EI. Мне нужно включить входящий запрос (т.е. XML) в это тело письма. если я использую тип контента как "text / html; charset = UTF-8", не получая контент XML. Но я использовал «text / plain; charset = UTF-8» в качестве Типа контента, точно получая то, что я хочу. Но я не могу отформатировать тело письма при использовании «text / plain». Может ли кто-нибудь помочь мне отправить «отформатированное тело письма с XML-контентом»? Замечания: Электронная почта отправлена ​​успешно и получает именно то, что я хочу. Но я не могу отформатировать текст письма, например, жирный, курсив и т. Д.

Отправка почты с помощью Gmail Connector

API-код:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/sendMail" name="MailSenderAPI" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST">
        <inSequence>
            <log level="custom">
                <property name="WelocmeLogger" value="======MailSenderAPI Started====="/>
            </log>
            <property description="Incoming request" expression="$body/*" name="InputRequest" />
            <log level="custom">
            <property expression="$body/*" name="RequestPayload"/>
            </log>
            <property description="ASGReadFromEmailBody-ServiceConfig" expression="get-property('QRSag_GmailConfiguration')" name="tokenConfig" scope="axis2" type="OM"/>
            <property description="accessToken" expression="$axis2:tokenConfig//*[local-name()='accessToken']" name="accessToken" scope="default" type="STRING"/>
            <property description="userId" expression="$axis2:tokenConfig//*[local-name()='userId']" name="userId" scope="default" type="STRING"/>
            <property description="refreshToken" expression="$axis2:tokenConfig//*[local-name()='refreshToken']" name="refreshToken" scope="default" type="STRING"/>
            <property description="registryPath" expression="$axis2:tokenConfig//*[local-name()='registryPath']" name="registryPath" scope="default" type="STRING"/>
            <property description="clientSecret" expression="$axis2:tokenConfig//*[local-name()='clientSecret']" name="clientSecret" scope="default" type="STRING"/>
            <property description="clientId" expression="$axis2:tokenConfig//*[local-name()='clientId']" name="clientId" scope="default" type="STRING"/>
            <property description="apiUrl" expression="$axis2:tokenConfig//*[local-name()='apiUrl']" name="apiUrl" scope="default" type="STRING"/>
            <property description="registryPath" expression="$axis2:tokenConfig//*[local-name()='registryPath']" name="registryPath" scope="default" type="STRING"/>
            <class name="com.qrsolutions.in.EmailContentMaker"/>
            <property description="mailingList" expression="get-property('QRSAG-CommonMailListing')" name="GetGamilID" scope="default" type="STRING"/>
             <!-- <property description="contentType" name="contentType" scope="default" type="STRING" value="text/html; charset=UTF-8"/>  -->
              <property description="contentType" name="contentType" scope="default" type="STRING" value="text/plain; charset=UTF-8"/>  

            <property name="Subject" scope="default" type="STRING" value="TEST:ASG-Lead Duplicate Records"/>
            <!-- <log level="custom">
                <property expression="$ctx:emailContent" name="EmailContent"/>
            </log> -->
            <gmail.init>
                <userId>me</userId>
                <accessToken>{$ctx:accessToken}</accessToken>
                <apiUrl>{$ctx:apiUrl}</apiUrl>
                <clientId>{$ctx:clientId}</clientId>
                <clientSecret>{$ctx:clientSecret}</clientSecret>
                <refreshToken>{$ctx:refreshToken}</refreshToken>
                <accessTokenRegistryPath>{$ctx:registryPath}</accessTokenRegistryPath>
            </gmail.init>
            <log level="full"/>
            <gmail.sendMail>
                <to>{$ctx:GetGamilID}</to>
                <subject>{$ctx:Subject}</subject>
                <from>asg.test@qrsolutions.com.au</from>
                <messageBody>{$ctx:emailContent}</messageBody>
                <contentType>{$ctx:contentType}</contentType>
            </gmail.sendMail>
            <log level="custom">
            <property name="Response" value="mail Sent Successfully"></property>
            </log>
            <payloadFactory media-type="json">
             <format>{"MailStatus":$1,"Message":"$2"}</format>
               <args>
                 <arg value="true"/>
                   <arg value="mail Sent Successfully"/>
               </args>
              </payloadFactory>
              <respond/>
            <!-- <property expression="get-property('GetGamilID')" name="To" scope="default" type="STRING"/>
            <property name="From" scope="default" type="STRING" value="asg.test@qrsolutions.com.au"/>
                <class name="com.qrsolutions.in.GmailSender"/>
                 <log level="custom">
                <property name="LoggerText" value="===Process Completed==="/>
            </log> -->
        </inSequence>
        <outSequence/>
        <faultSequence>
        <log level="custom">
        <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"></property>
        </log>
        <payloadFactory media-type="json">
             <format>{"MailStatus":$1,"Message":"$2"}</format>
               <args>
                 <arg value="false"/>
                   <arg expression="get-property('ERROR_MESSAGE')"/>
               </args>
              </payloadFactory>
              <respond/>
        </faultSequence>
    </resource>
</api>

EmailContentmaker-код:

```package com.qrsolutions.in;

import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;

import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;

public class EmailContentMaker extends AbstractMediator{

    @Override
    public boolean mediate(MessageContext context) {
        System.out.println("===Inside EmailContentMaker Class Mediator===");
        String InputRequest = checkNull((String) context.getProperty("InputRequest"));
        try{

        context.setProperty("emailContent", "Hi Team," +"\n\nWe are facing issue in Lead Process and \n\n" + "Request:" + "\n\n" + InputRequest
                + "\n\n" +"Let us know if you have any concerns.\n\nCheers,\nIntegration Team.");
        System.out.println("EmailContent: "+context.getProperty("emailContent"));
        }catch(Exception e)
        {
            e.printStackTrace();
            System.out.println("Reason for Exception:" +e.getMessage());
        }
        return true;
    }
    public static String checkNull(String input) {
        String retValue = input == null ? "" : input.equalsIgnoreCase("null") ? "" : input.trim();
        return retValue;
    }



}```

Запрос:

<InputData>
    <id>123</id>
    <name>JustinTest</name>
    <email>testMail@gmail.com</email>
</InputData>

Ожидаемый результат в теле письма:

Hi Team,

We are facing issue in Lead Process.
Request:
<InputData>
        <id>123</id>
        <name>JustinTest</name>
        <email>testMail@gmail.com</email>
</InputData>

Let us know if you have any concerns.

Cheers,
Integration Team.

--

1 Ответ

0 голосов
/ 18 июля 2019

Может быть, вы должны "... использовать тип контента как" text / html; charset = UTF-8 ".." и добавить какие-нибудь XML-символы без специальных символов в ваш EmailContentMaker? Ваш xml будет рассматриваться как отформатированный текст XML в вашем сообщении.

...