use of org.motechproject.email.domain.EmailRecord in project motech by motech.
the class EmailControllerTest method getTestEmailRecordsAsCsv.
private String getTestEmailRecordsAsCsv() {
List<EmailRecordDto> emailRecordDtos = new ArrayList<>();
for (EmailRecord email : getTestEmailRecords()) {
emailRecordDtos.add(new EmailRecordDto(email));
}
StringBuilder sb = new StringBuilder();
sb.append("Delivery Status,Delivery Time,From Address,To Address,Subject,Message\r\n");
for (EmailRecordDto dto : emailRecordDtos) {
sb.append(String.format("%s,%s,%s,%s,%s,%s\r\n", dto.getDeliveryStatus(), dto.getDeliveryTime(), dto.getFromAddress(), dto.getToAddress(), dto.getSubject(), dto.getMessage()));
}
return sb.toString();
}
use of org.motechproject.email.domain.EmailRecord in project motech by motech.
the class EmailSenderServiceImpl method send.
@Override
@Transactional
public void send(String fromAddress, String toAddress, String subject, String message) throws EmailSendException {
Mail mail = new Mail(fromAddress, toAddress, subject, message);
LOGGER.info(String.format("Sending message [%s] from [%s] to [%s] with subject [%s].", mail.getMessage(), mail.getFromAddress(), mail.getToAddress(), mail.getSubject()));
try {
mailSender.send(getMimeMessagePreparator(mail));
log(new EmailRecord(mail.getFromAddress(), mail.getToAddress(), mail.getSubject(), mail.getMessage(), now(), DeliveryStatus.SENT));
} catch (MailException e) {
log(new EmailRecord(mail.getFromAddress(), mail.getToAddress(), mail.getSubject(), mail.getMessage(), now(), DeliveryStatus.ERROR));
throw new EmailSendException("Unable to send an email to " + mail.getToAddress(), e);
}
}
use of org.motechproject.email.domain.EmailRecord in project motech by motech.
the class EmailController method getAvailableMonths.
@RequestMapping(value = "/emails/months/", method = RequestMethod.GET)
@PreAuthorize(EmailRolesConstants.HAS_ANY_EMAIL_ROLE)
@ResponseBody
public List<String> getAvailableMonths() {
List<String> availableMonths = new ArrayList<>();
List<EmailRecord> records = auditService.findAllEmailRecords();
for (EmailRecord record : records) {
String month = record.getDeliveryTime().monthOfYear().getAsText();
String year = record.getDeliveryTime().year().getAsText();
if (!availableMonths.contains(month + " " + year)) {
availableMonths.add(month + " " + year);
}
}
return availableMonths;
}
use of org.motechproject.email.domain.EmailRecord in project motech by motech.
the class EmailController method getAllFromAddressContaining.
private List<String> getAllFromAddressContaining(String partial) {
List<String> available = new ArrayList<>();
List<EmailRecord> records = auditService.findAllEmailRecords();
for (EmailRecord record : records) {
if (record.getFromAddress().contains(partial) && (!available.contains(record.getFromAddress()))) {
available.add(record.getFromAddress());
}
}
return available;
}
use of org.motechproject.email.domain.EmailRecord in project motech by motech.
the class EmailRecordServiceBundleIT method shouldCreateIdenticalMessages.
@Test
public void shouldCreateIdenticalMessages() {
DeliveryStatus deliveryStatus = DeliveryStatus.SENT;
String fromAddress = "f@adr";
String toAddress = "t@adr";
String subject = "test-subject";
String message = "test-message";
DateTime messageTime = DateUtil.now().toDateTime(DateTimeZone.UTC);
EmailRecord emailRecord = new EmailRecord(fromAddress, toAddress, subject, message, messageTime, deliveryStatus);
emailRecordService.create(emailRecord);
EmailRecord duplicateMessage = new EmailRecord(fromAddress, toAddress, subject, message, messageTime, deliveryStatus);
emailRecordService.create(duplicateMessage);
List<EmailRecord> allMessages = emailRecordService.findByRecipientAddress(toAddress);
assertEquals(2, allMessages.size());
}
Aggregations