如何在 wso2 EI 6.3.0 中使用"text/plain"作为内容类型格式化电子邮件正文?



我正在wso2 EI中发送电子邮件通知。我需要将传入请求(即XML)包含在该电子邮件正文中。如果我使用内容类型作为"文本/html;字符集=UTF-8"未获取 XML 内容。但我使用了"文本/纯文本;charset=UTF-8"作为内容类型,不包括得到我想要的东西。但是我无法使用"文本/纯文本"来格式化这些电子邮件正文。 任何人都可以帮我发送"带有XML内容的格式化电子邮件正文"吗? 注意: 电子邮件发送成功,并获得我想要的内容。但是我无法格式化电子邮件正文,如粗体,斜体等。

使用 Gmail 连接器发送邮件

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>

电子邮件内容制作者代码:

```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," +"nnWe are facing issue in Lead Process and nn" + "Request:" + "nn" + InputRequest
+ "nn" +"Let us know if you have any concerns.nnCheers,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.
--

可能是,你应该"...使用内容类型作为"文本/HTML;charset=UTF-8".." 并在您的 EmailContentMaker 中添加一些 XML 转义的特殊字符?您的 xml 将在邮件中显示为格式化的 XML 文本。

相关内容

最新更新