package org.datacite.mds.service.impl;

import java.util.concurrent.Future;

import org.apache.log4j.Logger;
import org.datacite.mds.domain.AllocatorOrDatacentre;
import org.datacite.mds.mail.MailMessage;
import org.datacite.mds.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

@Service
public class MailServiceImpl implements MailService {

    Logger log4j = Logger.getLogger(MailServiceImpl.class);

    @Autowired
    MailSender mailSender;

    public void send(MailMessage mail) {
        log4j.info("Sending mail: " + mail);
        mailSender.send(mail);
    }
    
    @Async
    public Future<Object> sendAsync(MailMessage mail) {
        send(mail);
        return new AsyncResult<Object>(null);
    }

}

@@ -106,62 +106,8 @@
 er;%0A
-import org.datacite.mds.domain.AllocatorOrDatacentre;%0A
 impo
@@ -252,16 +252,63 @@
 owired;%0A
+import org.springframework.mail.MailException;%0A
 import o
@@ -759,24 +759,42 @@
  %22 + mail);%0A
+        try %7B%0A    
         mail
@@ -808,24 +808,131 @@
 send(mail);%0A
+        %7D catch (MailException e) %7B%0A            log4j.warn(e.getMessage());%0A            throw e;%0A        %7D%0A
     %7D%0A    %0A 

add logging of mail exceptions