FileDocCategorySizeDatePackage
SendTag.javaAPI DocGlassfish v2 API4574Mon Oct 17 14:54:30 BST 2005demo

SendTag

public class SendTag extends BodyTagSupport
Custom tag for sending messages.

Fields Summary
private String
body
private String
cc
private String
host
private String
recipients
private String
sender
private String
subject
Constructors Summary
Methods Summary
public intdoEndTag()
Method for processing the end of the tag.

        Properties props = System.getProperties();
        
        try {
            if (host != null)
                props.put("mail.smtp.host", host);
            else if (props.getProperty("mail.smtp.host") == null)
                props.put("mail.smtp.host", InetAddress.getLocalHost().
                    getHostName());
        } catch (Exception ex) {
            throw new JspException(ex.getMessage());
        }
        Session session = Session.getDefaultInstance(props, null);
		
	Message msg = new MimeMessage(session);
	InternetAddress[] toAddrs = null, ccAddrs = null;

        try {
	    if (recipients != null) {
	        toAddrs = InternetAddress.parse(recipients, false);
	        msg.setRecipients(Message.RecipientType.TO, toAddrs);
	    } else
	        throw new JspException("No recipient address specified");

            if (sender != null)
                msg.setFrom(new InternetAddress(sender));
            else
                throw new JspException("No sender address specified");

	    if (cc != null) {
                ccAddrs = InternetAddress.parse(cc, false);
	        msg.setRecipients(Message.RecipientType.CC, ccAddrs);
	    }

	    if (subject != null)
	        msg.setSubject(subject);

	    if ((body = getBodyContent().getString()) != null)
	        msg.setText(body);
            else
                msg.setText("");

            Transport.send(msg);
	
        } catch (Exception ex) {
            throw new JspException(ex.getMessage());
        }

        return(EVAL_PAGE);
   
public voidsetCc(java.lang.String cc)
cc attribute setter method.

        this.cc = cc;
    
public voidsetHost(java.lang.String host)
host attribute setter method.

        this.host = host;
    
public voidsetRecipients(java.lang.String recipients)
recipient attribute setter method.

        this.recipients = recipients;
    
public voidsetSender(java.lang.String sender)
sender attribute setter method.

        this.sender = sender;
    
public voidsetSubject(java.lang.String subject)
subject attribute setter method.

        this.subject = subject;