Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add replyTo parameter to message and email closures to… OD-18383 #1107

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ class MailDeliveryParam {
private GetAddresses getAddressesBCC
private GetSubject getSubject
private GetContent getContent
private GetAddresses getAddressesReplyTo
private Date sentDate = new Date()

private MailDeliveryParam() {

}

static MailDeliveryParam valueOf(GetFrom getFrom, GetEnvelopeFrom getEnvelopeFrom, GetAddresses getAddressesTO, GetSubject getSubject, GetContent getContent) {
valueOf(getFrom, getEnvelopeFrom, getAddressesTO, GetAddresses.empty(), GetAddresses.empty(), getSubject, getContent)
valueOf(getFrom, getEnvelopeFrom, getAddressesTO, GetAddresses.empty(), GetAddresses.empty(), getSubject, getContent, GetAddresses.empty())
}

static MailDeliveryParam valueOf(GetFrom getFrom,
Expand All @@ -39,7 +40,8 @@ class MailDeliveryParam {
GetAddresses getAddressesCC,
GetAddresses getAddressesBCC,
GetSubject getSubject,
GetContent getContent) {
GetContent getContent,
GetAddresses getAddressesReplyTo) {
MailDeliveryParam param = new MailDeliveryParam()
param.getFrom = getFrom
param.getEnvelopeFrom = getEnvelopeFrom
Expand All @@ -48,6 +50,7 @@ class MailDeliveryParam {
param.getAddressesBCC = getAddressesBCC
param.getSubject = getSubject
param.getContent = getContent
param.getAddressesReplyTo = getAddressesReplyTo
param
}

Expand Down Expand Up @@ -82,4 +85,8 @@ class MailDeliveryParam {
GetEnvelopeFrom getGetEnvelopeFrom() {
return getEnvelopeFrom
}

GetAddresses getGetAddressesReplyTo() {
return getAddressesReplyTo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MailDeliveryService {
message.setHeader(EMAIL_HEADER, "onCourse ${angelVersion}".toString())
message.sentDate = param.sentDate
message.content = param.getContent.get()
message.setReplyTo(param.getAddressesReplyTo.get())

if (SMTPService.Mode.mock != smtpService.mode) {
Transport.send(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package ish.oncourse.server.scripting.api

import groovy.transform.CompileStatic
import groovy.transform.TypeCheckingMode
import ish.oncourse.API
import ish.oncourse.server.cayenne.Contact
import ish.oncourse.server.cayenne.SystemUser
import ish.oncourse.server.messaging.DocumentParam
Expand Down Expand Up @@ -78,6 +79,14 @@ import org.apache.cayenne.PersistentObject
* keyCollision "drop"
* }
* ```
* You can specify email addresses that recipients will reply to instead of the from address:
* ```
* email {
* template "Enrolment Confirmation"
* bindings enrolment: e
* to c
* replyTo "[email protected]" "[email protected]"
* }
*/
@Deprecated
@CompileStatic
Expand All @@ -99,6 +108,7 @@ class EmailSpec {
List<String> bccList = []
String multipartType = SMTPMessage.DEFAULT_MULTIPART_TYPE
List<DocumentParam> attachments = []
List<String> replyToList = []


/**
Expand Down Expand Up @@ -276,4 +286,16 @@ class EmailSpec {
void attachment(Map<String, Object> attachment) {
this.attachments << DocumentParam.valueOf((String) attachment.fileName, (String) attachment.type, attachment.content)
}


/**
* Set replyTo emails for the message.
* Using this method means that recipients will reply to these email addresses instead of the from address.
*
* @param remail addresses of the reply recipients
*/
@API
void replyTo(String... replyToEmails) {
this.replyToList = replyToEmails.toList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ import org.apache.cayenne.PersistentObject
* keyCollision "drop"
* }
* ```
*
* You can specify email addresses that recipients will reply to instead of the from address for emails:
* ```
* message {
* template keyCodeOfMessageTemplate
* record records
* from "[email protected]"
* replyTo "[email protected]" "[email protected]"
* }
* ```
*/
@API
@CompileDynamic
Expand All @@ -143,6 +153,8 @@ class MessageSpec {
String fromName
String content

List<String> replyToList = []


/**
* Set message template to be used for rendering message body.
Expand Down Expand Up @@ -415,4 +427,16 @@ class MessageSpec {
def arg = args.find()
bindings.put(key, arg)
}


/**
* Set replyTo emails for the message.
* Using this method means that recipients will reply to these email addresses instead of the from address.
*
* @param remail addresses of the reply recipients
*/
@API
void replyTo(String... replyToEmails) {
this.replyToList = replyToEmails.toList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SmtpParameters {
List<DocumentParam> attachments
String templateIdentifier
Map<String, Object> bindings
List<String> replyToList = []

SmtpParameters(EmailSpec spec) {
fromAddress = spec.fromAddress
Expand All @@ -46,6 +47,7 @@ class SmtpParameters {
attachments = spec.attachments
templateIdentifier = spec.templateName
bindings = spec.bindings
replyToList = spec.replyToList
}

SmtpParameters(MessageSpec spec) {
Expand All @@ -60,6 +62,7 @@ class SmtpParameters {
spec.bccList.each { bccList.add(it) }
attachments = spec.attachments
templateIdentifier = spec.templateIdentifier
replyToList = spec.replyToList
bindings = spec.bindings
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ public MailDeliveryParam build(){
var getAddressesTO = GetAddresses.valueOf(parameters.getToList());
var getAddressesCC = GetAddresses.valueOf(parameters.getCcList());
var getAddressesBCC = GetAddresses.valueOf(parameters.getBccList());
var getAddressesReplyTo = GetAddresses.valueOf(parameters.getReplyToList());
var getSubject = GetSubject.valueOf(templateService, parameters.getTemplateIdentifier(), parameters.getBindings(), parameters.getSubject());
var getEmailPlainBody = GetEmailPlainBody.valueOf(templateService, parameters.getTemplateIdentifier(), parameters.getBindings(), parameters.getContent());
var getEmailHtmlBody = GetEmailHtmlBody.valueOf(templateService, parameters.getTemplateIdentifier(), parameters.getBindings());
var getContent = GetContent.valueOf(getEmailPlainBody, getEmailHtmlBody, parameters.getAttachments());

return MailDeliveryParam.valueOf(getFrom, getEnvelopeFrom, getAddressesTO, getAddressesCC, getAddressesBCC, getSubject, getContent);
return MailDeliveryParam.valueOf(getFrom, getEnvelopeFrom, getAddressesTO, getAddressesCC, getAddressesBCC, getSubject, getContent, getAddressesReplyTo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void send() {
var getSubject = GetSubject.valueOf(subject);
var getContent = getContentFunction();

var mailDeliveryParam = MailDeliveryParam.valueOf(getFrom, getEnvelopeFrom, getAddressesTO, getAddressesCC, getAddressesBCC, getSubject, getContent);
var mailDeliveryParam = MailDeliveryParam.valueOf(getFrom, getEnvelopeFrom, getAddressesTO, getAddressesCC, getAddressesBCC, getSubject, getContent, GetAddresses.empty());

mailDeliveryService.sendEmail(mailDeliveryParam);

Expand Down