Track email response

Submitted by:Jhon Brain

Date added:27 April, 2014

Category:Java

Code example for tracking email response

Tags: email tracking , email response

Code Snippet:

    String cacheId = req.getParameter("cache_id");
String nameInEmail = req.getParameter("name_in_email");

// find EmailMessage by cache_id
EmailMessage emailMessage = emailMessageService.findBy(cacheId);

// find BroadcastReceiverChannelDestination by channel, broadcast_id, destination, receiver_id
BroadcastReceiverChannelDestination brcd = brcdService.findBy("EMAIL", emailMessage.getBroadcast().getId(), emailMessage.getReceiverEmail(), emailMessage.getReceiver().getId());

// get current BroadcastResponseOption of user
BroadcastResponseOption curRespOpt = brcd.getResponse();

// find BroadcastResponseOption by broadcast_id and name_in_email (received BroadcastResponseOption from user)
BroadcastResponseOption newRespOpt = broadcastResponseOptionService.findBy(emailMessage.getBroadcast().getId(), nameInEmail);

// detect ResponseMessageTemplateType
ResponseMessageTemplateType respType;
if (broadcast.getExpiryDateTime().before(new Date())) {
respType = ResponseMessageTemplateType.ResponseReceived; // received after deadline
} else if (null == curRespOpt) {
respType = ResponseMessageTemplateType.NewResponse; // new response
} else if (!newRespOpt.getNameInEmail().equalsIgnoreCase(curRespOpt.getNameInEmail())) {
respType = ResponseMessageTemplateType.ResponseChanged; // change response
} else if (newRespOpt.getNameInEmail().equalsIgnoreCase(curRespOpt.getNameInEmail())) {
respType = ResponseMessageTemplateType.ResponseDuplicated; // duplicated response
}

// one BroadcastResponseOption has a list of ResponseMessageTemplate (NewResponse, ResponseChanged,...)
List<ResponseMessageTemplate> lstRespMsgTempl = bRespOpt.getResponseOption().getResponseMessageTemplates();
for (ResponseMessageTemplate respMsgTempl : lstRespMsgTempl) {
if (respType == respMsgTempl.getType()) {
// get email to send
String emailSubject = respMsgTempl.getMessageTemplate().getEmailSubject();
String emailContent = respMsgTempl.getMessageTemplate().getEmailContent();

// send email
boolean sendingResult = broadcastWorker.sendEmail(emailMessage.getReceiverEmail(), emailSubject, emailContent);

// action after responding
ActionAfterResponding action = respMsgTempl.getActionAfterResponding();
if (null != action) {
// Custom page
if (ActionAfterRespondingType.Page == action.getType()) {
String displayContent = action.getContent();
} else if (ActionAfterRespondingType.Link == action.getType()) { // redirect to link
String redirectLink = action.getContent();
}
}
}
}
 
 

Comments