Accessing SMTP Connections

If you create a property named smtpr of type SMTP Resource Template, TIBCO Business Studio adds the following to the abstract implementation class:
import org.osoa.sca.annotations.Property;
import javax.mail.Session;

private Session smtpr;

	@Property(name = "smtpr")
	public void setSmtpr(Session smtpr) {
		this.smtpr = smtpr;
	}

	public Session getSmtpr() {
		return smtpr;
	}

Procedure

  • Invoke the accessor methods in your component implementation.

Example

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
...
	Transport transport =null;
	try{
		Session session = getSmtpr();
		transport = session.getTransport();
		Message message = new MimeMessage(session);
	    message.setFrom(new InternetAddress(mailFrom));
	    InternetAddress dests[] = new InternetAddress[]{ new InternetAddress(mailTo) };
	    message.setRecipients(Message.RecipientType.TO, dests);
	    message.setSubject(subject);
    
	    message.setDataHandler(new DataHandler(new ByteArrayDataSource(
			requestContent, "text/plain")));
	    transport.connect();
	    transport.sendMessage(message, dests);    	 
		} catch(Exception exp){
			...
		}
			return false;
		} finally {
			 if (transport != null)
				try {
					transport.close();
				} catch (MessagingException e) {
					e.printStackTrace();
				}
			}
		}	
		return true;
...