/* * Copyright (C) 2003 Peter Jonathan Klauser. All rights reserved. * * This software is published under the terms of the Jumpi Software * License version 1.1, a copy of which has been included with this * distribution in the LICENSE-jumpi.txt file. * */ package org.jumpi.examples.email; import org.jumpi.Destination; import org.jumpi.Handle; import org.jumpi.Jumpi; import org.jumpi.examples.JumpiClientApplication; import org.jumpi.examples.JumpiClientApplicationRunner; import org.jumpi.impl.connector.email.EmailDestination; import java.util.Hashtable; import javax.mail.MessagingException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; /** * Send Email messages via SMTP. */ public class EmailSender implements JumpiClientApplication { /** The runner. */ JumpiClientApplicationRunner runner_ = null; /** * Set the runner. * * @param runner the runner. */ public void setJumpiClientApplicationRunner( JumpiClientApplicationRunner runner) { runner_ = runner; } /** * Return the configuration values to use in doWork(). * * @return the configuration values to use. */ public Hashtable getConfiguration() { Hashtable config = new Hashtable(); config.put("org.jumpi.configurationloader", "org.jumpi.impl.ConfigurationLoader"); config.put("org.jumpi.controller", "stateless"); config.put("org.jumpi.controller.stateless.classname", "org.jumpi.impl.controller.stateless.StatelessController"); config.put("org.jumpi.controller.stateless.connector", "email"); config.put("org.jumpi.controller.stateless.connector.email.classname", "org.jumpi.impl.connector.email.EmailConnector"); config.put("org.jumpi.controller.stateless.connector.email.protocol", "email"); config.put("org.jumpi.controller.stateless.connector.email.smtphost", "smtp.freesurf.ch"); config.put("org.jumpi.controller.stateless.connector.email.defaultfrom", "test@jumpi.org"); return config; } /** * Run the example code. * * @param j the started, configured Jumpi instance to use in the example. */ public void doWork(Jumpi j) { // get a Destination representing an Email recipient Destination recipient = j.getDestination("email://peter.klauser@freesurf.ch"); // a simple send scenario - dont need any MimeMessage or javax.mail imports // set the subject explicitly as client properties Hashtable props = new Hashtable(); props.put("email.subject", "email subject - simple send." ); // synchronously send a message. Handle simpleSendStatus = j.send(recipient, "email text content - simple send.", props); // print out information about the status of the operation. runner_.evaluateHandle(simpleSendStatus); // a MimeMessage can be used instead of a simple text message - but this // must first be retrieved from an EmailDestination // the full features of the MimeMessage - multiple different content types // can still be used. MimeMessage mimeMsg = ((EmailDestination)recipient).getMimeMessage(); try { // adding a recipient overrides the email recipient in the jumpi.send mimeMsg.addRecipient(MimeMessage.RecipientType.TO, new InternetAddress("peter.klauser@freesurf.ch")); mimeMsg.setSubject("email subject - mime send."); mimeMsg.setText("email text content - mime send."); // synchronously send a message. Handle mimeSendStatus = j.send(recipient, mimeMsg); // print out information about the status of the operation. runner_.evaluateHandle(mimeSendStatus); } catch ( MessagingException e ) { runner_.log("MimeSend Exception: " + e); } } } /* * Version History * $Log: $ */