Java 在ApacheCamelAPI中,如何知道哪个电子邮件接收失败是由于什么原因
我正在使用apache camel api发送电子邮件Java 在ApacheCamelAPI中,如何知道哪个电子邮件接收失败是由于什么原因,java,apache-camel,Java,Apache Camel,我正在使用apache camel api发送电子邮件 public boolean sendEmail(JSONObject data) { boolean status=false; camel = new DefaultCamelContext(); template = camel.createProducerTemplate(); Map<String, Ob
public boolean sendEmail(JSONObject data)
{
boolean status=false;
camel = new DefaultCamelContext();
template = camel.createProducerTemplate();
Map<String, Object> map = new HashMap<String, Object>();
map.put("To",data.getString("toaddress"));
String body = data.getString("body");
map.put("Subject", data.getString("subject"));
map.put("From", "xxxxxxx@yahoo.com");
template.sendBodyAndHeaders("smtps://smtp.gmail.com?username=sxxx@gmail.com&password=ixxx", body, map);
status=true;
return status;
}
public boolean sendmail(JSONObject数据)
{
布尔状态=假;
camel=新的DefaultCamelContext();
模板=camel.createProducerTemplate();
Map Map=newhashmap();
map.put(“To”,data.getString(“toaddress”);
String body=data.getString(“body”);
map.put(“Subject”,data.getString(“Subject”);
map.put(“From”xxxxxxx@yahoo.com");
template.sendBodyAndHeaders(“smtps://smtp.gmail.com?username=sxxx@gmail.com&password=ixxx“,正文,地图);
状态=真;
返回状态;
}
这段代码在发送单回执和多回执时运行良好,但问题是,我如何知道哪封电子邮件回执失败以及失败的原因是什么。我是apache camel的新手,所以我不知道apache camel是否在证明 您已使用
ProducerTemplate.html#sendboyandheaders(java.lang.String、java.lang.Object、java.util.Map)
将主体发送到端点。根据文档,如果交换处理失败,此方法将抛出cameleExecutionException
。所以,把这段代码放在try-catch块中
public boolean sendEmail(JSONObject data)
{
boolean status=false;
camel = new DefaultCamelContext();
template = camel.createProducerTemplate();
Map<String, Object> map = new HashMap<String, Object>();
map.put("To",data.getString("toaddress"));
String body = data.getString("body");
map.put("Subject", data.getString("subject"));
map.put("From", "xxxxxxx@yahoo.com");
try{
template.sendBodyAndHeaders("smtps://smtp.gmail.com?username=sxxx@gmail.com&password=ixxx", body, map);
}catch(CamelExecutionException camelExecException){
logger.error("Error occured during sending body to end point :"+ camelExecException.getMessage());
}
}
public boolean sendmail(JSONObject数据)
{
布尔状态=假;
camel=新的DefaultCamelContext();
模板=camel.createProducerTemplate();
Map Map=newhashmap();
map.put(“To”,data.getString(“toaddress”);
String body=data.getString(“body”);
map.put(“Subject”,data.getString(“Subject”);
map.put(“From”xxxxxxx@yahoo.com");
试一试{
template.sendBodyAndHeaders(“smtps://smtp.gmail.com?username=sxxx@gmail.com&password=ixxx“,正文,地图);
}捕获(CamleExecutionException CamleExecutionException){
logger.error(“将正文发送到端点时发生错误:+camelexeception.getMessage());
}
}
这将帮助您发现什么时候出现了失败以及失败背后的原因。希望这对我有所帮助我是apache camel的新手,所以你能告诉我需要修改代码的实际位置吗?对于一个收据,它工作正常。如果出现任何错误,则会生成异常,但当我发送到多个收据时,它不会引发任何异常,即使电子邮件id无效CamelExecutionException只有在代码无法执行时才会发生进行交换的处理。对于无效的电子邮件id或exchange处理后的任何问题,它不会抛出CamleExecutionException。所以我要做的是。当我发送到多个收据时,我想知道哪个收据失败。是否可能?您可以使用其他返回类型的方法来执行发送工作。因此,您可以使用返回类型来评估它是否成功。