在 Mule CE 3.5.0 中发送带有 java 的电子邮件
Send an email with java in Mule CE 3.5.0
我正在尝试使用 java
我遇到的问题在 Mule CE 中发送电子邮件:
1. 我想从这个 json
文件中获取收件人的电子邮件 https://gist.githubusercontent.com/Rajeun/b550fe17181610f5c0f0/raw/934bf1e621d6bc056f20dee653dac74275026ba5/file.json "I don't know how to do it".
2.下我post我的尝试:
Xml 文件:
<flow name="cronsFlow2" >
<quartz:inbound-endpoint responseTimeout="10000" doc:name="Quartz" jobName="HTTP-Puller-Scheduler" repeatInterval="5000" repeatCount="0">
<quartz:event-generator-job>
<quartz:payload>HTTP Puller</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<https:outbound-endpoint exchange-pattern="request-response" host="gist.githubusercontent.com" port="443" method="GET" doc:name="HTTP" encoding="UTF-8" mimeType="application/json" path="Rajeun/b550fe17181610f5c0f0/raw/934bf1e621d6bc056f20dee653dac74275026ba5/file.json"/>
<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/>
<choice doc:name="Choice">
<when expression="#[message.payload.sent]">
<logger message="#[message.payloadAs(java.lang.String)]+ HELLO" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<set-variable variableName="email" value="#[message.payload.email]" doc:name="Variable"/>
<component class="pushv.SendMail" doc:name="Java"/>
<logger message="Error" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
</flow>
还有我的 代码 java
:
package pushv;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
public static void main(String[] args) {
final String username = "<Frommail>@gmail.com";
final String password = "pass";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("<Frommail>@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("<TomailfromJson>@gmail.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
错误:
ERROR 2015-03-29 17:40:36,648 [[pushv].cronsFlow2.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Failed to find entry point for component, the following resolvers tried but failed: [
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
ReflectionEntryPointResolver: Could not find entry point on: "pushv.SendMail" with arguments: "{class java.util.LinkedHashMap}"
AnnotatedEntryPointResolver: Component: pushv.SendMail@13508f6 doesn't have any annotated methods, skipping.
CallableEntryPointResolver: Object "pushv.SendMail@13508f6" does not implement required interface "interface org.mule.api.lifecycle.Callable"
]
Code : MULE_ERROR-321
--------------------------------------------------------------------------------
Exception stack is:
1. Failed to find entry point for component, the following resolvers tried but failed: [
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
ReflectionEntryPointResolver: Could not find entry point on: "pushv.SendMail" with arguments: "{class java.util.LinkedHashMap}"
AnnotatedEntryPointResolver: Component: pushv.SendMail@13508f6 doesn't have any annotated methods, skipping.
CallableEntryPointResolver: Object "pushv.SendMail@13508f6" does not implement required interface "interface org.mule.api.lifecycle.Callable"
] (org.mule.model.resolvers.EntryPointNotFoundException)
org.mule.model.resolvers.DefaultEntryPointResolverSet:49 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/model/resolvers/EntryPointNotFoundException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.model.resolvers.EntryPointNotFoundException: Failed to find entry point for component, the following resolvers tried but failed: [
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
ReflectionEntryPointResolver: Could not find entry point on: "pushv.SendMail" with arguments: "{class java.util.LinkedHashMap}"
AnnotatedEntryPointResolver: Component: pushv.SendMail@13508f6 doesn't have any annotated methods, skipping.
CallableEntryPointResolver: Object "pushv.SendMail@13508f6" does not implement required interface "interface org.mule.api.lifecycle.Callable"
]
at org.mule.model.resolvers.DefaultEntryPointResolverSet.invoke(DefaultEntryPointResolverSet.java:49)
at org.mule.component.DefaultComponentLifecycleAdapter.invoke(DefaultComponentLifecycleAdapter.java:339)
at org.mule.component.AbstractJavaComponent.invokeComponentInstance(AbstractJavaComponent.java:82)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
请帮忙。提前谢谢你。
问题是您正在使用 Java class 并在 class 中使用 public static void main(String[] args)
这就是它失败并且无法找到方法的原因打电话
无需使用 Java 文件并使其变得复杂,您可以简单地使用 smtp out bound,如下所示和 set-payload :-
<set-payload value="Dear Mail Crawler,
\n\n No spam to my email, please!" doc:name="Set Payload"/>
<smtp:outbound-endpoint host="smtp.gmail.com" port="587"
user="myemail%40gmail.com" password="pass" to= "#[message.payload.email]"
from="Rajeun" subject="Testing Subject" responseTimeout="10000" connector-ref="Gmail" doc:name="Send notification email"/>
PS:- 如果您想使用 java class 发送电子邮件,请从 java [=37] 中删除 public static void main(String[] args)
=] 并使用入口点解析器调用您的方法(如果您的 java class 包含多个方法)
参考:- http://blogs.mulesoft.org/mule-school-invoking-component-methods-using-entry-point-resolvers/
更新的答案
将以下内容放在顶部:-
<smtp:gmail-connector name="Gmail" validateConnections="true" doc:name="Gmail" contentType="text/html; charset=UTF-8"/>
然后在使用 connector-ref="Gmail"
和 smtp 出站的流程中使用以下内容:-
<smtp:outbound-endpoint host="smtp.gmail.com" port="587" responseTimeout="10000" doc:name="SMTP" connector-ref="Gmail" from="Rajeun" password="pass" subject="Mule Test with Velocity Transformer"
to="#[flowVars['email']]" user="myemail%40gmail.com" />
我正在尝试使用 java
我遇到的问题在 Mule CE 中发送电子邮件:
1. 我想从这个 json
文件中获取收件人的电子邮件 https://gist.githubusercontent.com/Rajeun/b550fe17181610f5c0f0/raw/934bf1e621d6bc056f20dee653dac74275026ba5/file.json "I don't know how to do it".
2.下我post我的尝试:
Xml 文件:
<flow name="cronsFlow2" >
<quartz:inbound-endpoint responseTimeout="10000" doc:name="Quartz" jobName="HTTP-Puller-Scheduler" repeatInterval="5000" repeatCount="0">
<quartz:event-generator-job>
<quartz:payload>HTTP Puller</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<https:outbound-endpoint exchange-pattern="request-response" host="gist.githubusercontent.com" port="443" method="GET" doc:name="HTTP" encoding="UTF-8" mimeType="application/json" path="Rajeun/b550fe17181610f5c0f0/raw/934bf1e621d6bc056f20dee653dac74275026ba5/file.json"/>
<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/>
<choice doc:name="Choice">
<when expression="#[message.payload.sent]">
<logger message="#[message.payloadAs(java.lang.String)]+ HELLO" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<set-variable variableName="email" value="#[message.payload.email]" doc:name="Variable"/>
<component class="pushv.SendMail" doc:name="Java"/>
<logger message="Error" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
</flow>
还有我的 代码 java
:
package pushv;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
public static void main(String[] args) {
final String username = "<Frommail>@gmail.com";
final String password = "pass";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("<Frommail>@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("<TomailfromJson>@gmail.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
错误:
ERROR 2015-03-29 17:40:36,648 [[pushv].cronsFlow2.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Failed to find entry point for component, the following resolvers tried but failed: [
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
ReflectionEntryPointResolver: Could not find entry point on: "pushv.SendMail" with arguments: "{class java.util.LinkedHashMap}"
AnnotatedEntryPointResolver: Component: pushv.SendMail@13508f6 doesn't have any annotated methods, skipping.
CallableEntryPointResolver: Object "pushv.SendMail@13508f6" does not implement required interface "interface org.mule.api.lifecycle.Callable"
]
Code : MULE_ERROR-321
--------------------------------------------------------------------------------
Exception stack is:
1. Failed to find entry point for component, the following resolvers tried but failed: [
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
ReflectionEntryPointResolver: Could not find entry point on: "pushv.SendMail" with arguments: "{class java.util.LinkedHashMap}"
AnnotatedEntryPointResolver: Component: pushv.SendMail@13508f6 doesn't have any annotated methods, skipping.
CallableEntryPointResolver: Object "pushv.SendMail@13508f6" does not implement required interface "interface org.mule.api.lifecycle.Callable"
] (org.mule.model.resolvers.EntryPointNotFoundException)
org.mule.model.resolvers.DefaultEntryPointResolverSet:49 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/model/resolvers/EntryPointNotFoundException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.model.resolvers.EntryPointNotFoundException: Failed to find entry point for component, the following resolvers tried but failed: [
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
ReflectionEntryPointResolver: Could not find entry point on: "pushv.SendMail" with arguments: "{class java.util.LinkedHashMap}"
AnnotatedEntryPointResolver: Component: pushv.SendMail@13508f6 doesn't have any annotated methods, skipping.
CallableEntryPointResolver: Object "pushv.SendMail@13508f6" does not implement required interface "interface org.mule.api.lifecycle.Callable"
]
at org.mule.model.resolvers.DefaultEntryPointResolverSet.invoke(DefaultEntryPointResolverSet.java:49)
at org.mule.component.DefaultComponentLifecycleAdapter.invoke(DefaultComponentLifecycleAdapter.java:339)
at org.mule.component.AbstractJavaComponent.invokeComponentInstance(AbstractJavaComponent.java:82)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
请帮忙。提前谢谢你。
问题是您正在使用 Java class 并在 class 中使用 public static void main(String[] args)
这就是它失败并且无法找到方法的原因打电话
无需使用 Java 文件并使其变得复杂,您可以简单地使用 smtp out bound,如下所示和 set-payload :-
<set-payload value="Dear Mail Crawler,
\n\n No spam to my email, please!" doc:name="Set Payload"/>
<smtp:outbound-endpoint host="smtp.gmail.com" port="587"
user="myemail%40gmail.com" password="pass" to= "#[message.payload.email]"
from="Rajeun" subject="Testing Subject" responseTimeout="10000" connector-ref="Gmail" doc:name="Send notification email"/>
PS:- 如果您想使用 java class 发送电子邮件,请从 java [=37] 中删除 public static void main(String[] args)
=] 并使用入口点解析器调用您的方法(如果您的 java class 包含多个方法)
参考:- http://blogs.mulesoft.org/mule-school-invoking-component-methods-using-entry-point-resolvers/
更新的答案
将以下内容放在顶部:-
<smtp:gmail-connector name="Gmail" validateConnections="true" doc:name="Gmail" contentType="text/html; charset=UTF-8"/>
然后在使用 connector-ref="Gmail"
和 smtp 出站的流程中使用以下内容:-
<smtp:outbound-endpoint host="smtp.gmail.com" port="587" responseTimeout="10000" doc:name="SMTP" connector-ref="Gmail" from="Rajeun" password="pass" subject="Mule Test with Velocity Transformer"
to="#[flowVars['email']]" user="myemail%40gmail.com" />