Merge branch 'mailExceptionFix' into develop
This commit is contained in:
commit
33d658e5f9
@ -7,13 +7,12 @@ import java.util.Set;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.SendFailedException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.sun.mail.smtp.SMTPSendFailedException;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.GeneralSystemSettingsDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.MailEventDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.MailEvent;
|
||||
@ -65,7 +64,7 @@ public class MailEventWorker extends AbstractWorker {
|
||||
replyToEmails[i] = u.getEmailAddress();
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
if( generalSystemSettingsDao.getGeneralSystemSettingsInstance().isMailNotifications() ){ //If false, mail-events "vanish"
|
||||
logger.debug("Sending mail notification to: "+recipients);
|
||||
mail.mail(fromName, fromEmail, recipientsEmails, replyToEmails, subject, messageBody, false);
|
||||
@ -75,19 +74,26 @@ public class MailEventWorker extends AbstractWorker {
|
||||
|
||||
this.commitTransaction();
|
||||
|
||||
} catch(SMTPSendFailedException e){
|
||||
} catch(SendFailedException e){
|
||||
// We need to catch this exception for the use case when one or
|
||||
// more of the recipients are invalid, to make sure we still
|
||||
// send the mail to the valid recipients, and delete the mail
|
||||
// event to prevent spamming.
|
||||
// event to prevent spamming.
|
||||
logger.info("Could not send mail to all of the recipients, more info:");
|
||||
if(e.getInvalidAddresses()!=null){
|
||||
for(Address a : e.getInvalidAddresses()) {
|
||||
logger.info("Message could not be sent to the following invalid address: "+a.toString());
|
||||
}
|
||||
}
|
||||
if(e.getValidSentAddresses()!=null){
|
||||
for(Address a : e.getValidSentAddresses()){
|
||||
logger.info("Message have been sent to the following valid address: "+a.toString());
|
||||
}
|
||||
}
|
||||
if(e.getValidUnsentAddresses()!=null){
|
||||
for(Address a : e.getValidUnsentAddresses()){
|
||||
logger.info("Message have not been sent to the following valid address: "+a.toString());
|
||||
}
|
||||
}
|
||||
mailEvent = mailEventDao.reLoad(mailEvent);
|
||||
mailEventDao.delete(mailEvent);
|
||||
|
Loading…
x
Reference in New Issue
Block a user