@Test public void testEachRecipientOnToForSendMailAsSeparateMails() { MailerResult result = null; int numberOfSeparateMails = recipients.size(); result = mailerWithTemplate.sendMailAsSeparateMails(recipients, null, null, template, ruedi); assertEquals(MailerResult.OK, result.getReturnCode()); verifyTimesCallingCreateAndSendMessageInvocationsFor(numberOfSeparateMails, recipients, null, null); }
public MailerResult sendMailAsSeparateMails(List<? extends OLATPrincipal> recipientsTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC, MailTemplate template, OLATPrincipal sender) { MailerResult result = new MailerResult(); if (webappAndMailHelper.getMailhost() == null) { result.setReturnCode(MailerResult.MAILHOST_UNDEFINED); log.warn("sendMailAsSeparateMails - webappAndMailHelper.getMailhost(): " + webappAndMailHelper.getMailhost()); return result; } boolean isMailSendToRecipient = false; if (recipientsTO != null) { for (OLATPrincipal recipient : recipientsTO) { VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, recipient, null, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (recipientsCC != null) { for (OLATPrincipal recipient : recipientsCC) { List<OLATPrincipal> cc = new ArrayList<OLATPrincipal>(); cc.add(recipient); VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, null, cc, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (recipientsBCC != null) { for (OLATPrincipal recipient : recipientsBCC) { VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, recipient, null, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (!isMailSendToRecipient) { if (result.getReturnCode() == MailerResult.OK) { result.setReturnCode(MailerResult.RECIPIENT_ADDRESS_ERROR); } log.warn("sendMailAsSeparateMails - result.getReturnCode(): " + result.getReturnCode() + " . See MailerResult for return codes."); } return result; }
MailerWithTemplate { public MailerResult sendMailAsSeparateMails(List<? extends OLATPrincipal> recipientsTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC, MailTemplate template, OLATPrincipal sender) { MailerResult result = new MailerResult(); if (webappAndMailHelper.getMailhost() == null) { result.setReturnCode(MailerResult.MAILHOST_UNDEFINED); log.warn("sendMailAsSeparateMails - webappAndMailHelper.getMailhost(): " + webappAndMailHelper.getMailhost()); return result; } boolean isMailSendToRecipient = false; if (recipientsTO != null) { for (OLATPrincipal recipient : recipientsTO) { VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, recipient, null, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (recipientsCC != null) { for (OLATPrincipal recipient : recipientsCC) { List<OLATPrincipal> cc = new ArrayList<OLATPrincipal>(); cc.add(recipient); VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, null, cc, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (recipientsBCC != null) { for (OLATPrincipal recipient : recipientsBCC) { VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, recipient, null, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (!isMailSendToRecipient) { if (result.getReturnCode() == MailerResult.OK) { result.setReturnCode(MailerResult.RECIPIENT_ADDRESS_ERROR); } log.warn("sendMailAsSeparateMails - result.getReturnCode(): " + result.getReturnCode() + " . See MailerResult for return codes."); } return result; } }
MailerWithTemplate { public MailerResult sendMailAsSeparateMails(List<? extends OLATPrincipal> recipientsTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC, MailTemplate template, OLATPrincipal sender) { MailerResult result = new MailerResult(); if (webappAndMailHelper.getMailhost() == null) { result.setReturnCode(MailerResult.MAILHOST_UNDEFINED); log.warn("sendMailAsSeparateMails - webappAndMailHelper.getMailhost(): " + webappAndMailHelper.getMailhost()); return result; } boolean isMailSendToRecipient = false; if (recipientsTO != null) { for (OLATPrincipal recipient : recipientsTO) { VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, recipient, null, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (recipientsCC != null) { for (OLATPrincipal recipient : recipientsCC) { List<OLATPrincipal> cc = new ArrayList<OLATPrincipal>(); cc.add(recipient); VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, null, cc, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (recipientsBCC != null) { for (OLATPrincipal recipient : recipientsBCC) { VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, recipient, null, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (!isMailSendToRecipient) { if (result.getReturnCode() == MailerResult.OK) { result.setReturnCode(MailerResult.RECIPIENT_ADDRESS_ERROR); } log.warn("sendMailAsSeparateMails - result.getReturnCode(): " + result.getReturnCode() + " . See MailerResult for return codes."); } return result; } private  MailerWithTemplate(); private  MailerWithTemplate(MailPackageStaticDependenciesWrapper webappAndMailHelper); }
MailerWithTemplate { public MailerResult sendMailAsSeparateMails(List<? extends OLATPrincipal> recipientsTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC, MailTemplate template, OLATPrincipal sender) { MailerResult result = new MailerResult(); if (webappAndMailHelper.getMailhost() == null) { result.setReturnCode(MailerResult.MAILHOST_UNDEFINED); log.warn("sendMailAsSeparateMails - webappAndMailHelper.getMailhost(): " + webappAndMailHelper.getMailhost()); return result; } boolean isMailSendToRecipient = false; if (recipientsTO != null) { for (OLATPrincipal recipient : recipientsTO) { VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, recipient, null, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (recipientsCC != null) { for (OLATPrincipal recipient : recipientsCC) { List<OLATPrincipal> cc = new ArrayList<OLATPrincipal>(); cc.add(recipient); VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, null, cc, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (recipientsBCC != null) { for (OLATPrincipal recipient : recipientsBCC) { VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, recipient, null, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (!isMailSendToRecipient) { if (result.getReturnCode() == MailerResult.OK) { result.setReturnCode(MailerResult.RECIPIENT_ADDRESS_ERROR); } log.warn("sendMailAsSeparateMails - result.getReturnCode(): " + result.getReturnCode() + " . See MailerResult for return codes."); } return result; } private  MailerWithTemplate(); private  MailerWithTemplate(MailPackageStaticDependenciesWrapper webappAndMailHelper); static MailerWithTemplate getInstance(); MailerResult sendMailUsingTemplateContext(OLATPrincipal recipientTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC,
            MailTemplate template, OLATPrincipal sender); String[] previewSubjectAndBody(OLATPrincipal recipientTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC,
            MailTemplate template, OLATPrincipal sender); MailerResult sendMail(OLATPrincipal recipientTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC,
            MailTemplate template, OLATPrincipal sender); MailerResult sendMailAsSeparateMails(List<? extends OLATPrincipal> recipientsTO, List<? extends OLATPrincipal> recipientsCC,
            List<? extends OLATPrincipal> recipientsBCC, MailTemplate template, OLATPrincipal sender); }
MailerWithTemplate { public MailerResult sendMailAsSeparateMails(List<? extends OLATPrincipal> recipientsTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC, MailTemplate template, OLATPrincipal sender) { MailerResult result = new MailerResult(); if (webappAndMailHelper.getMailhost() == null) { result.setReturnCode(MailerResult.MAILHOST_UNDEFINED); log.warn("sendMailAsSeparateMails - webappAndMailHelper.getMailhost(): " + webappAndMailHelper.getMailhost()); return result; } boolean isMailSendToRecipient = false; if (recipientsTO != null) { for (OLATPrincipal recipient : recipientsTO) { VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, recipient, null, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (recipientsCC != null) { for (OLATPrincipal recipient : recipientsCC) { List<OLATPrincipal> cc = new ArrayList<OLATPrincipal>(); cc.add(recipient); VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, null, cc, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (recipientsBCC != null) { for (OLATPrincipal recipient : recipientsBCC) { VelocityContext context = new VelocityContext(); template.putVariablesInMailContext(context, recipient); sendWithContext(context, recipient, null, null, template, sender, result); if (isMailSentToRecipient(result, recipient)) { isMailSendToRecipient = true; } } } if (!isMailSendToRecipient) { if (result.getReturnCode() == MailerResult.OK) { result.setReturnCode(MailerResult.RECIPIENT_ADDRESS_ERROR); } log.warn("sendMailAsSeparateMails - result.getReturnCode(): " + result.getReturnCode() + " . See MailerResult for return codes."); } return result; } private  MailerWithTemplate(); private  MailerWithTemplate(MailPackageStaticDependenciesWrapper webappAndMailHelper); static MailerWithTemplate getInstance(); MailerResult sendMailUsingTemplateContext(OLATPrincipal recipientTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC,
            MailTemplate template, OLATPrincipal sender); String[] previewSubjectAndBody(OLATPrincipal recipientTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC,
            MailTemplate template, OLATPrincipal sender); MailerResult sendMail(OLATPrincipal recipientTO, List<? extends OLATPrincipal> recipientsCC, List<? extends OLATPrincipal> recipientsBCC,
            MailTemplate template, OLATPrincipal sender); MailerResult sendMailAsSeparateMails(List<? extends OLATPrincipal> recipientsTO, List<? extends OLATPrincipal> recipientsCC,
            List<? extends OLATPrincipal> recipientsBCC, MailTemplate template, OLATPrincipal sender);  }