updated sender to validate a from address was provided and only adds a reply to if provided

This commit is contained in:
Tim Chamberlain
2024-05-02 11:16:11 -05:00
parent 9d669de989
commit 0651fa22af

View File

@ -173,6 +173,16 @@ public class RenderSavedReportExecuteStep implements BackendStep
if(!toEmailAddressList.isEmpty() && CollectionUtils.nullSafeHasContents(QContext.getQInstance().getMessagingProviders())) if(!toEmailAddressList.isEmpty() && CollectionUtils.nullSafeHasContents(QContext.getQInstance().getMessagingProviders()))
{ {
///////////////////////////////////////////
// error if no from address was provided //
///////////////////////////////////////////
if(!StringUtils.hasContent(fromEmailAddress))
{
String message = "Could not send an email because no from email address was provided.";
LOG.error(message);
throw (new QException(message));
}
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// since sending email, make s3 file publicly accessible // // since sending email, make s3 file publicly accessible //
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -187,14 +197,21 @@ public class RenderSavedReportExecuteStep implements BackendStep
recipients.addParty(new Party().withAddress(toAddress).withRole(EmailPartyRole.TO)); recipients.addParty(new Party().withAddress(toAddress).withRole(EmailPartyRole.TO));
} }
///////////////
// add froms //
///////////////
MultiParty froms = new MultiParty();
froms.addParty(new Party().withAddress(fromEmailAddress).withRole(EmailPartyRole.FROM));
if(StringUtils.hasContent(replyToEmailAddress))
{
froms.addParty(new Party().withAddress(replyToEmailAddress).withRole(EmailPartyRole.REPLY_TO));
}
String downloadURL = storageAction.getDownloadURL(storageInput); String downloadURL = storageAction.getDownloadURL(storageInput);
new SendMessageAction().execute(new SendMessageInput() new SendMessageAction().execute(new SendMessageInput()
.withMessagingProviderName(sesProviderName) .withMessagingProviderName(sesProviderName)
.withTo(recipients) .withTo(recipients)
.withFrom(new MultiParty() .withFrom(froms)
.withParty(new Party().withAddress(fromEmailAddress).withRole(EmailPartyRole.FROM))
.withParty(new Party().withAddress(replyToEmailAddress).withRole(EmailPartyRole.REPLY_TO))
)
.withSubject(StringUtils.hasContent(emailSubject) ? emailSubject : downloadFileBaseName) .withSubject(StringUtils.hasContent(emailSubject) ? emailSubject : downloadFileBaseName)
.withContent(new Content().withContentRole(EmailContentRole.TEXT).withBody("To download your report, open this URL in your browser: " + downloadURL)) .withContent(new Content().withContentRole(EmailContentRole.TEXT).withBody("To download your report, open this URL in your browser: " + downloadURL))
.withContent(new Content().withContentRole(EmailContentRole.HTML).withBody("Link: <a target=\"_blank\" href=\"" + downloadURL + "\" download>" + downloadFileName + "</a>")) .withContent(new Content().withContentRole(EmailContentRole.HTML).withBody("Link: <a target=\"_blank\" href=\"" + downloadURL + "\" download>" + downloadFileName + "</a>"))