01: package email;
02:
03: import org.enhydra.shark.api.internal.toolagent.AppParameter;
04:
05: import java.util.Properties;
06: import javax.mail.*;
07: import javax.mail.internet.*;
08:
09: /** MailProc sends an e-mail using specified parameters:
10: *
11: * param1 - text_msg The text of the message
12: * param2 - subject Subject of the e-mail
13: * param3 - source_address Address of the sender (XXX@XXXX.XXX)
14: * param4 - destination_address Address of the receiver (XXX@XXXX.XXX)
15: * param5 - user If the server requires athentication
16: * Can be an empty string ""
17: * param6 - password Password the user needs to authenticate
18: * Can be an empty string ""
19: * param7 - server IP address of de server
20: * param8 - port Number of the port (usually 25)
21: *
22: * @throws MessagingException If exists an error while sending the message
23: *
24: * @author Paloma Trigueros Cabezon
25: * @version 1.0
26: */
27:
28: public class MailProc {
29: public static void execute(AppParameter param1,
30: AppParameter param2, AppParameter param3,
31: AppParameter param4, AppParameter param5,
32: AppParameter param6, AppParameter param7,
33: AppParameter param8) {
34: try {
35: System.out.println("Beginning MailProc...");
36:
37: //Extracting parameters
38: System.out.println("Extracting parameters...");
39:
40: /* This is an example of how to send a number (the result of
41: a calculation, for example) as the text of the message:
42: long text = param1.extract_longlong();
43: Long t = new Long(text);
44: String text_msg = t.toString(text);
45: */
46:
47: String text_msg = param1.the_value.toString();
48: String subject = param2.the_value.toString();
49: String source_address = param3.the_value.toString();
50: String destination_address = param4.the_value.toString();
51: String user = param5.the_value.toString();
52: String password = param6.the_value.toString();
53: String server = param7.the_value.toString();
54: long port = ((Long) param8.the_value).longValue();
55:
56: // Get system properties
57: Properties props = new Properties();
58:
59: // Setup mail server
60: props.put("mail.smtp.host", server);
61: props.put("mail.smtp.port", "" + port);
62:
63: // User name
64: props.put("mail.smtp.user", user);
65: props.put("mail.smtp.auth", "true");
66:
67: // Get session
68: javax.mail.Session session = Session.getInstance(props,
69: new SmtpAuthenticator(user, password));
70:
71: // Define message
72: MimeMessage message = new MimeMessage(session);
73:
74: message.setFrom(new InternetAddress(source_address));
75:
76: message.addRecipient(Message.RecipientType.TO,
77: new InternetAddress(destination_address));
78:
79: message.setSubject(subject);
80:
81: message.setContent(text_msg, "text/plain");
82:
83: // Send message
84: Transport.send(message);
85:
86: } catch (Exception ex) {
87: System.out
88: .println("MailProc - Problems during execution of MailProc"
89: + ex);
90: }
91: System.out.println("Finishing MailProc...");
92: }
93: }
|