E-mail sevice sendEmail ignores cc and bcc in EmailInfo

Hello,
I’m trying to set cc and bcc EmailInfo parameters to send an e-mail, but it doesn’t work, cc and bcc are ignored. It works for To, and for multiple recipients in To separated by semicolon.
During the debug session I can see that emailInfo has been properly set before emailService.sendEmail is called.

This is the code in question(HashMap<String, Serializable> templateParameters is built prior to this )

InputDialog emailDialog = dialogs.createInputDialog(this)
        .withCaption("Send this via e-mail")
        .withParameters(
                InputParameter.stringParameter("subject")
                        .withCaption("Subject:").withRequired(true).withDefaultValue("Case: " + test1Str + " " + test2Str),
                InputParameter.stringParameter("to")
                        .withCaption("To:").withRequired(true).withDefaultValue(email4report),
                InputParameter.stringParameter("cc")
                        .withCaption("CC:"),
                InputParameter.stringParameter("bcc")
                        .withCaption("BCC:")
                )
        .withActions(DialogActions.OK_CANCEL)
        .withCloseListener(closeEvent -> {
            if (closeEvent.closedWith(DialogOutcome.OK)) {
                String subject = closeEvent.getValue("subject");
                String to = closeEvent.getValue("to");
                String cc = closeEvent.getValue("cc");
                String bcc = closeEvent.getValue("bcc");
                EmailInfo emailInfo = EmailInfoBuilder.create()
                        .setCaption(subject)
                        .setAddresses(to)
                        .setCc(cc)
                        .setBcc(bcc)
                        .setFrom(email4report)
                        .setTemplatePath("com/company/test1/templates/template1.txt")
                        .setTemplateParameters(templateParameters)
                        .build();
                try {
                    emailService.sendEmail(emailInfo);
                } catch (EmailException e) {
                    e.printStackTrace();
                }
            }
        })
        .show();

}

There seems to have been youtrack case How to specify CC and BCC email addresses to EmailInfo

Can anyone send cc and bcc with success?

Thanks
Mladen

Hi,
Take a look at the JavaDoc of the EmailInfo#setCc() method:

    /**
     *  Result of this method call (i.e., setting addresses of the email CC field) is ignored during the message creation if
     *  {@link com.haulmont.cuba.core.global.EmailInfo#isSendInOneMessage()} returns {@code false} (default behaviour),
     *  because, in this case, the message is generated for each of the recipients separately.
     */
    public void setCc(String cc) {
        this.cc = cc;
    }

So you need to call EmailInfo.setSendInOneMessage(true).

1 Like

Thank you.