0

i am sending the email using apache camel api.

   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; 

    } 

This code is working fine for sending single receipt as well as multiple receipt but the problem is that how do i know which email receipt is fail and for what reason.i am new in apache camel so i do not know whether apache camel is proving or not?

4

1 回答 1

0

您曾经ProducerTemplate.html#sendBodyAndHeaders(java.lang.String, java.lang.Object, java.util.Map)将正文发送到端点。根据文档,此方法将抛出CamelExecutionException- 如果交换处理失败。所以,把这段代码放在 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());
        }
}

这将帮助您找到何时出现故障及其背后的原因。希望这可以帮助

于 2013-10-24T06:02:02.407 回答