MailChimpSender { public void listSubscribe(String emailAddress, Map<String, Object> vars) throws MailException { if ( !emailConfig.isMailChimpEnabled() ) { logger.info("MailChimp usage is not enabled!"); return; } try { boolean result = mailJimpService.listSubscribe( emailConfig.getMailChimpListId(), emailAddress, vars, EmailType.HTML, emailConfig.isMailChimpDoubleOpt(), false, false, true ); if ( result ) { logger.info("MailChimp listSubscribe() succeeded"); } else { logger.info("MailChimp listSubscribe() failed"); } } catch (MailJimpException ex) { logger.error("MailChimp error (status code: " + ex.getStatusCode() + ")", ex); int errorCode = GeneralException.GENERAL_ERROR; String message = ex.getMessage(); Pattern pattern = Pattern.compile("Code: (.*?)\\."); Matcher matcher = pattern.matcher(message); if ( matcher.find() ) { String code = matcher.group(1); if ( code.equals("214") ) { errorCode = MailException.ALREADY_SUBSCRIBED; } } throw new MailException(errorCode, ex); } }  void listSubscribe(String emailAddress, Map<String, Object> vars);  }
@Test @Ignore public void listSubscribeTest() throws MailException { String emailAddress = "venefica.labs@yatko.com"; Map<String, Object> vars = new HashMap<String, Object>(0); vars.put("INVITATION", "1234"); vars.put("ZIPCODE", "00501"); vars.put("SOURCE", "Other"); vars.put("USERTYPE", UserType.GIVER.getDescription()); mailChimpSender.listSubscribe(emailAddress, vars); }