1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class JavaUDF extends com.ibm.db2.app.StoredProc
{
public JavaUDF()
{}
public static String mailer(String email, String subject, String message)
{
try
{
// Specify our host, intended recipient, & sender e-mail address
String host = "10.191.15.10";
InternetAddress from = new InternetAddress("moi@domain.com");
InternetAddress recipient = new InternetAddress(email);
// Get the system properties
Properties props = new Properties();
// Setup default parameters - the protocol, the host, and port #
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.host",host);
props.put("mail.smtp.port","25");
// Create session
Session mySession = Session.getInstance(props);
// Create our message
MimeMessage myMessage = new MimeMessage(mySession);
myMessage.setFrom(from);
myMessage.setSubject(subject);
myMessage.setText(message);
myMessage.addRecipient(Message.RecipientType.TO,recipient);
// Send the message
javax.mail.Transport.send(myMessage);
}
catch (Exception e)
{
System.out.println("An error has occurred: " + e);
return "An error has occurred: " + e;
}
return "An E-mail was sent to " + email;
}
} |
Partager