From d64a104445b9fbcc47739d8ec56de4e88009f404 Mon Sep 17 00:00:00 2001 From: Mitch Gaffigan Date: Fri, 7 Aug 2026 19:16:27 -0500 Subject: [PATCH] Add support for CC and BCC to SmtpSender Signed-off-by: Mitch Gaffigan --- .../connect/connectors/smtp/SmtpSender.java | 24 +++++++++++++++++-- .../connectors/smtp/SmtpConnectorServlet.java | 2 ++ .../DefaultConfigurationController.java | 10 ++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/client/src/main/java/com/mirth/connect/connectors/smtp/SmtpSender.java b/client/src/main/java/com/mirth/connect/connectors/smtp/SmtpSender.java index d8be4c8235..085fdfe0a8 100644 --- a/client/src/main/java/com/mirth/connect/connectors/smtp/SmtpSender.java +++ b/client/src/main/java/com/mirth/connect/connectors/smtp/SmtpSender.java @@ -112,6 +112,8 @@ public ConnectorProperties getProperties() { properties.setUsername(usernameField.getText()); properties.setPassword(new String(passwordField.getPassword())); properties.setTo(toField.getText()); + properties.setCc(ccField.getText()); + properties.setBcc(bccField.getText()); properties.setFrom(fromField.getText()); properties.setSubject(subjectField.getText()); @@ -185,6 +187,8 @@ public void setProperties(ConnectorProperties properties) { usernameField.setText(props.getUsername()); passwordField.setText(props.getPassword()); toField.setText(props.getTo()); + ccField.setText(props.getCc()); + bccField.setText(props.getBcc()); fromField.setText(props.getFrom()); subjectField.setText(props.getSubject()); @@ -257,13 +261,13 @@ public boolean checkProperties(ConnectorProperties properties, boolean highlight errors.append("\"Send Timeout\" is required\n"); } - if (props.getTo().length() == 0) { + if (StringUtils.isBlank(props.getTo()) && StringUtils.isBlank(props.getCc()) && StringUtils.isBlank(props.getBcc())) { valid = false; if (highlight) { toField.setBackground(UIConstants.INVALID_COLOR); } - errors.append("\"To\" is required\n"); + errors.append("At least one of \"To\", \"CC\", or \"BCC\" is required\n"); } if (props.getFrom().length() == 0) { @@ -695,6 +699,12 @@ public void actionPerformed(ActionEvent evt) { toLabel = new JLabel("To:"); toField = new MirthTextField(); + ccLabel = new JLabel("CC:"); + ccField = new MirthTextField(); + + bccLabel = new JLabel("BCC:"); + bccField = new MirthTextField(); + fromLabel = new JLabel("From:"); fromField = new MirthTextField(); @@ -828,6 +838,8 @@ private void initToolTips() { usernameField.setToolTipText("If the SMTP server requires authentication to send a message, enter the username here."); passwordField.setToolTipText("If the SMTP server requires authentication to send a message, enter the password here."); toField.setToolTipText("The name of the mailbox (person, usually) to which the email should be sent."); + ccField.setToolTipText("Addresses to carbon copy the email to."); + bccField.setToolTipText("Addresses to blind carbon copy the email to."); fromField.setToolTipText("The name that should appear as the \"From address\" in the email."); subjectField.setToolTipText("The text that should appear as the subject of the email, as seen by the receiver's email client."); charsetEncodingComboBox.setToolTipText(String.format("Select the character set encoding used by the sender of the message,
or Default to assume the default character set encoding for the JVM running %s.", BrandingConstants.PRODUCT_NAME)); @@ -875,6 +887,10 @@ private void initLayout() { add(passwordField, "w 125!, sx"); add(toLabel, "newline, right"); add(toField, "w 200!, sx"); + add(ccLabel, "newline, right"); + add(ccField, "w 200!, sx"); + add(bccLabel, "newline, right"); + add(bccField, "w 200!, sx"); add(fromLabel, "newline, right"); add(fromField, "w 200!, sx"); add(subjectLabel, "newline, right"); @@ -1035,6 +1051,10 @@ private void useHeadersVariableFieldsEnabled(boolean useVariable) { private MirthPasswordField passwordField; private JLabel toLabel; private MirthTextField toField; + private JLabel ccLabel; + private MirthTextField ccField; + private JLabel bccLabel; + private MirthTextField bccField; private JLabel fromLabel; private MirthTextField fromField; private JLabel subjectLabel; diff --git a/server/src/main/java/com/mirth/connect/connectors/smtp/SmtpConnectorServlet.java b/server/src/main/java/com/mirth/connect/connectors/smtp/SmtpConnectorServlet.java index a48e36228c..c5d0cf093a 100644 --- a/server/src/main/java/com/mirth/connect/connectors/smtp/SmtpConnectorServlet.java +++ b/server/src/main/java/com/mirth/connect/connectors/smtp/SmtpConnectorServlet.java @@ -43,6 +43,8 @@ public ConnectionTestResponse sendTestEmail(String channelId, String channelName props.put("username", replacer.replaceValues(properties.getUsername(), channelId, channelName)); props.put("password", replacer.replaceValues(properties.getPassword(), channelId, channelName)); props.put("toAddress", replacer.replaceValues(properties.getTo(), channelId, channelName)); + props.put("ccAddress", replacer.replaceValues(properties.getCc(), channelId, channelName)); + props.put("bccAddress", replacer.replaceValues(properties.getBcc(), channelId, channelName)); props.put("fromAddress", replacer.replaceValues(properties.getFrom(), channelId, channelName)); return configurationController.sendTestEmail(props); diff --git a/server/src/main/java/com/mirth/connect/server/controllers/DefaultConfigurationController.java b/server/src/main/java/com/mirth/connect/server/controllers/DefaultConfigurationController.java index bfee2eddbf..92cacd87b8 100644 --- a/server/src/main/java/com/mirth/connect/server/controllers/DefaultConfigurationController.java +++ b/server/src/main/java/com/mirth/connect/server/controllers/DefaultConfigurationController.java @@ -1636,6 +1636,8 @@ public ConnectionTestResponse sendTestEmail(Properties properties) throws Except String username = properties.getProperty("username"); String password = properties.getProperty("password"); String to = properties.getProperty("toAddress"); + String cc = properties.getProperty("ccAddress"); + String bcc = properties.getProperty("bccAddress"); String from = properties.getProperty("fromAddress"); int port = -1; @@ -1690,6 +1692,14 @@ public ConnectionTestResponse sendTestEmail(Properties properties) throws Except email.addTo(toAddress); } + for (String ccAddress : StringUtils.split(cc, ",")) { + email.addCc(ccAddress); + } + + for (String bccAddress : StringUtils.split(bcc, ",")) { + email.addBcc(bccAddress); + } + email.setFrom(from); email.setMsg(String.format( "Receipt of this email confirms that mail originating from this %s Server is capable of reaching its intended destination.\n\nSMTP Configuration:\n- Host: %s\n- Port: %d",