Changeset 738:b602f977d4a6
- Timestamp:
- 10/12/09 13:07:02 (4 years ago)
- Author:
- tgambet
- Branch:
- default
- convert_revision:
- svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@739
- Message:
-
added logger
+email address validity check
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r723
|
r738
|
|
| 1 | | // $Id: Mail.java,v 1.3 2009-10-09 11:13:10 tgambet Exp $ |
| | 1 | // $Id: Mail.java,v 1.4 2009-10-12 13:07:02 tgambet Exp $ |
| 2 | 2 | // Author: Thomas Gambet |
| 3 | 3 | // (c) COPYRIGHT MIT, ERCIM and Keio, 2009. |
| … |
… |
|
| 14 | 14 | import java.util.Properties; |
| 15 | 15 | |
| 16 | | import javax.mail.Address; |
| 17 | 16 | import javax.mail.Authenticator; |
| 18 | 17 | import javax.mail.MessagingException; |
| 19 | 18 | import javax.mail.Session; |
| 20 | 19 | import javax.mail.Transport; |
| | 20 | import javax.mail.internet.AddressException; |
| 21 | 21 | import javax.mail.internet.InternetAddress; |
| 22 | 22 | import javax.mail.internet.MimeBodyPart; |
| … |
… |
|
| 24 | 24 | import javax.mail.internet.MimeMultipart; |
| 25 | 25 | |
| | 26 | import org.apache.commons.logging.Log; |
| | 27 | import org.apache.commons.logging.LogFactory; |
| 26 | 28 | import org.w3c.unicorn.exceptions.UnicornException; |
| 27 | 29 | import org.w3c.unicorn.output.FileOutputFormater; |
| … |
… |
|
| 30 | 32 | public class Mail { |
| 31 | 33 | |
| | 34 | private static Log logger = LogFactory.getLog(Mail.class); |
| | 35 | |
| 32 | 36 | public void sendMail(String[] recipients, String subject, List<OutputFormater> outputFormaters, Map<String, Object> contextObjects) throws UnicornException { |
| 33 | 37 | |
| … |
… |
|
| 47 | 51 | msg.setFrom(addressFrom); |
| 48 | 52 | |
| 49 | | Address[] recipientAdresses = new Address[recipients.length]; |
| | 53 | List<InternetAddress> validAddresses = new ArrayList<InternetAddress>(); |
| | 54 | |
| | 55 | for (String recipient : recipients) { |
| | 56 | try { |
| | 57 | InternetAddress address = new InternetAddress(recipient); |
| | 58 | validAddresses.add(address); |
| | 59 | } catch(AddressException e) { |
| | 60 | logger.warn("Invalid address: \"" + recipient + "\". Skipping."); |
| | 61 | } |
| | 62 | } |
| | 63 | |
| | 64 | InternetAddress[] recipientsAddresses = new InternetAddress[validAddresses.size()]; |
| 50 | 65 | int i = 0; |
| 51 | | for (String recipient : recipients) { |
| 52 | | recipientAdresses[i] = new InternetAddress(recipient); |
| | 66 | for (InternetAddress add : validAddresses) { |
| | 67 | recipientsAddresses[i] = add; |
| 53 | 68 | i++; |
| 54 | 69 | } |
| 55 | | msg.setRecipients(javax.mail.Message.RecipientType.TO, recipientAdresses); |
| | 70 | |
| | 71 | msg.setRecipients(javax.mail.Message.RecipientType.TO, recipientsAddresses); |
| 56 | 72 | msg.setSubject(subject); |
| 57 | 73 | |