gpt4 book ai didi

java - 使用 Mule esb 发送电子邮件

转载 作者:行者123 更新时间:2023-11-30 08:18:47 25 4
gpt4 key购买 nike

我必须对“已发送”变量进行测试,如果它为假,那么我必须发送一封电子邮件,这是我的代码:

<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="gist.githubusercontent.com" port="443" doc:name="HTTP Request Configuration"/>
<smtp:gmail-connector name="Gmail" validateConnections="true" doc:name="Gmail"/>
<flow name="push3Flow">
<quartz:inbound-endpoint jobName="HTTP-Puller-Scheduler" repeatInterval="5000" responseTimeout="10000" doc:name="Quartz" repeatCount="0">
<quartz:event-generator-job/>
</quartz:inbound-endpoint>
<http:request config-ref="HTTP_Request_Configuration" path="Rajeun/b550fe17181610f5c0f0/raw/9cf0940d1b534220a4e50493f42a70e2f4a20584/file.json" method="GET" doc:name="HTTP"/>
<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/>
<choice doc:name="Choice">
<when expression="#[(message.payload.sent) &amp;&amp; (message.payload.email != &quot;&quot;)]">
<logger level="INFO" doc:name="Logger" message="its ok"/>
</when>
<otherwise>
<component doc:name="Java" class="Component1"/>
<smtp:outbound-endpoint host="smtp.gmail.com" port="587"
user="myemail%40gmail.com" password="pass" to= "<Json-email>@gmail.com"
from="Rajeun" subject="Testing mule" responseTimeout="10000" connector-ref="Gmail" doc:name="Send notification email"/>
</otherwise>
</choice>
</flow>

Java 类:

import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;


public class Component1 implements Callable{


@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
eventContext.getMessage().setPayload("This is email Body ");
return eventContext.getMessage();
}

}

我的 json 文件:

https://gist.githubusercontent.com/Rajeun/b550fe17181610f5c0f0/raw/3f5eaeea955b6eb56bc4715f535fa8bb6d7ab798/file.json

我想要做的是自动从 json 文件中获取电子邮件(与我指定的 token 关联的电子邮件)。当我尝试这个时:

 <smtp:outbound-endpoint host="smtp.gmail.com" port="587" 
user="myemail%40gmail.com" password="pass" to= "#[payload.email]"
from="Rajeun" subject="Testing mule" responseTimeout="10000" connector-ref="Gmail" doc:name="Send notification email"/>

它表明“电子邮件地址”为空我怎样才能做到这一点?!预先感谢您。

最佳答案

不要使用#[payload.email]使用#[message.payload.email]如下:-

<smtp:outbound-endpoint host="smtp.gmail.com" port="587" 
user="myemail%40gmail.com" password="pass" to= "#[message.payload.email]"
from="Rajeun" subject="Testing mule" responseTimeout="10000" connector-ref="Gmail" doc:name="Send notification email"/>

#[payload.email]因为有时有效负载会无缘无故地失败..所以最好使用 #[message.payload.email]

你的表情也应该是 <when expression="#[message.payload.sent &amp;&amp; message.payload.email != &quot;&quot;]">

编辑版本

<set-variable variableName="email" value="#[message.payload.email]" doc:name="Variable"/>
<component doc:name="Java" class="Component1"/>
<smtp:outbound-endpoint host="smtp.gmail.com" port="587"
user="myemail%40gmail.com" password="pass" to= "#[flowVars['email']]"
from="Rajeun" subject="Testing mule" responseTimeout="10000" connector-ref="Gmail" doc:name="Send notification email"/>

设置 #[message.payload.email]在名为 email 的变量中,然后在 smtp 组件中使用变量 email ,如上所示

关于java - 使用 Mule esb 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29275723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com