1 | /*
|
---|
2 | * Created on Jan 1, 2005
|
---|
3 | * Copyright (C) 2004, 2005 Andrea Schweer
|
---|
4 | *
|
---|
5 | * This file is part of the Greenstone Alerting Service.
|
---|
6 | * Refer to the COPYING file in the base directory of this package
|
---|
7 | * for licensing information.
|
---|
8 | */
|
---|
9 | package org.greenstone.gsdlas.util;
|
---|
10 |
|
---|
11 | import java.util.Properties;
|
---|
12 |
|
---|
13 | import javax.mail.*;
|
---|
14 | import javax.mail.internet.InternetAddress;
|
---|
15 | import javax.mail.internet.MimeMessage;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * @author schweer
|
---|
19 | *
|
---|
20 | * TODO To change the template for this generated type comment go to
|
---|
21 | * Window - Preferences - Java - Code Style - Code Templates
|
---|
22 | */
|
---|
23 | public class Mailer {
|
---|
24 |
|
---|
25 | private String fromAddress;
|
---|
26 | private String mailHost;
|
---|
27 |
|
---|
28 | public Mailer (String from, String host) {
|
---|
29 | fromAddress = from;
|
---|
30 | mailHost = host;
|
---|
31 | }
|
---|
32 |
|
---|
33 | public void sendMail(String to, String subject, String message) throws MessagingException {
|
---|
34 | // Set the host smtp address
|
---|
35 | Properties props = new Properties();
|
---|
36 | props.put("mail.smtp.host", mailHost);
|
---|
37 |
|
---|
38 | // create some properties and get the default Session
|
---|
39 | //Session session = Session.getDefaultInstance(props, null);
|
---|
40 | Session session = Session.getInstance(props);
|
---|
41 |
|
---|
42 | // create a message
|
---|
43 | Message msg = new MimeMessage(session);
|
---|
44 |
|
---|
45 | // set the from and to address
|
---|
46 | InternetAddress addressFrom = new InternetAddress(fromAddress);
|
---|
47 | msg.setFrom(addressFrom);
|
---|
48 |
|
---|
49 | InternetAddress[] addressTo = new InternetAddress[1];
|
---|
50 | addressTo[0] = new InternetAddress(to);
|
---|
51 | msg.setRecipients(Message.RecipientType.TO, addressTo);
|
---|
52 |
|
---|
53 | // Setting the Subject and Content Type
|
---|
54 | msg.setSubject(subject);
|
---|
55 | msg.setContent(message, "text/plain");
|
---|
56 | Transport.send(msg);
|
---|
57 | }
|
---|
58 | }
|
---|