01: /*
02: * SalomeTMF is a Test Management Framework
03: * Copyright (C) 2005 France Telecom R&D
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * @author Marche Mikael
20: *
21: * Contact: mikael.marche@orange-ftgroup.com
22: */
23:
24: package org.objectweb.salome_tmf.api;
25:
26: import javax.mail.*;
27: import javax.mail.internet.*;
28: import java.util.*;
29:
30: public class Mail {
31:
32: public static void postMail(String recipients[], String subject,
33: String message, String from) throws Exception {
34: Properties props = new Properties();
35: if (Api.mail_host == null) {
36: return;
37: } else {
38:
39: props.put("mail.smtp.host", Api.mail_host);
40: }
41: // create some properties and get the default Session
42: Session session = Session.getDefaultInstance(props, null);
43:
44: // create a message
45: Message msg = new MimeMessage(session);
46:
47: // set the from and to address
48: InternetAddress addressFrom = new InternetAddress(from);
49: msg.setFrom(addressFrom);
50:
51: InternetAddress[] addressTo = new InternetAddress[recipients.length];
52: for (int i = 0; i < recipients.length; i++) {
53: addressTo[i] = new InternetAddress(recipients[i]);
54: }
55: msg.setRecipients(Message.RecipientType.TO, addressTo);
56:
57: // Optional : You can also set your custom headers in the Email if you Want
58: //msg.addHeader("MyHeaderName", "myHeaderValue");
59:
60: // Setting the Subject and Content Type
61: msg.setSubject(subject);
62: msg.setContent(message, "text/plain");
63: Transport.send(msg);
64:
65: }
66: }
|