org.browsecode.helpers
Class SendMail

java.lang.Object
  extended by org.browsecode.helpers.SendMail

public class SendMail
extends java.lang.Object

msgsendsample sends a simple email message.

usage: java msgsendsample to from smtphost true|false where to and from are the destination and origin email addresses, respectively, and smtphost is the hostname of the machine that has the smtp server running. The last parameter either turns on or turns off debugging during sending. Originally based off code by Max Spivak at Sun.


Constructor Summary
SendMail()
           
SendMail(java.lang.String messageSubject)
           
SendMail(java.lang.String theMessage, java.lang.String messageTo, java.lang.String messageSubject)
           
SendMail(java.lang.String theMessage, java.lang.String messageTo, java.lang.String messageFrom, java.lang.String messageSubj)
           
 
Method Summary
 void addSMTPServer(java.lang.String smtpServerDomainName)
           
 java.lang.String getBody()
           
 javax.mail.internet.InternetAddress getFrom()
           
 java.lang.String getLastErrorMessage()
           
 java.lang.String getSubject()
           
 javax.mail.internet.InternetAddress[] getTo()
           
static java.lang.String sendEmail(java.lang.String[] possibleSmtpHosts, javax.mail.internet.InternetAddress from, javax.mail.internet.InternetAddress[] to, java.lang.String subject, java.lang.String body)
           
protected static java.lang.String sendEmailJavaStandard(java.lang.String smtpHost, javax.mail.internet.InternetAddress from, javax.mail.internet.InternetAddress[] to, java.lang.String subject, java.lang.String body)
          Send an email.
 boolean sendMessage()
           
 void setBody(java.lang.String theText)
           
 void setFrom(javax.mail.internet.InternetAddress from)
           
 void setFrom(java.lang.String from)
           
 void setSubject(java.lang.String subject)
           
 void setTo(javax.mail.internet.InternetAddress toAddress)
           
 void setTo(javax.mail.internet.InternetAddress[] toAddress)
           
 void setTo(java.lang.String toAddress)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SendMail

public SendMail(java.lang.String theMessage,
                java.lang.String messageTo,
                java.lang.String messageFrom,
                java.lang.String messageSubj)
         throws javax.mail.internet.AddressException
Throws:
javax.mail.internet.AddressException

SendMail

public SendMail(java.lang.String theMessage,
                java.lang.String messageTo,
                java.lang.String messageSubject)
         throws javax.mail.internet.AddressException
Throws:
javax.mail.internet.AddressException

SendMail

public SendMail(java.lang.String messageSubject)
         throws javax.mail.internet.AddressException
Throws:
javax.mail.internet.AddressException

SendMail

public SendMail()
Method Detail

addSMTPServer

public void addSMTPServer(java.lang.String smtpServerDomainName)

setTo

public void setTo(java.lang.String toAddress)
           throws javax.mail.internet.AddressException
Throws:
javax.mail.internet.AddressException

getTo

public javax.mail.internet.InternetAddress[] getTo()

setFrom

public void setFrom(java.lang.String from)
             throws javax.mail.internet.AddressException
Throws:
javax.mail.internet.AddressException

getFrom

public javax.mail.internet.InternetAddress getFrom()

setTo

public void setTo(javax.mail.internet.InternetAddress toAddress)

setTo

public void setTo(javax.mail.internet.InternetAddress[] toAddress)

setFrom

public void setFrom(javax.mail.internet.InternetAddress from)

setSubject

public void setSubject(java.lang.String subject)

getSubject

public java.lang.String getSubject()

setBody

public void setBody(java.lang.String theText)

getBody

public java.lang.String getBody()

sendEmailJavaStandard

protected static java.lang.String sendEmailJavaStandard(java.lang.String smtpHost,
                                                        javax.mail.internet.InternetAddress from,
                                                        javax.mail.internet.InternetAddress[] to,
                                                        java.lang.String subject,
                                                        java.lang.String body)
Send an email.

Parameters:
smtpHost -
from -
to -
subject -
body -
Returns:
null if the message sent successfully, a string with an error message if it failed to send.

sendEmail

public static java.lang.String sendEmail(java.lang.String[] possibleSmtpHosts,
                                         javax.mail.internet.InternetAddress from,
                                         javax.mail.internet.InternetAddress[] to,
                                         java.lang.String subject,
                                         java.lang.String body)

getLastErrorMessage

public java.lang.String getLastErrorMessage()
Returns:

sendMessage

public boolean sendMessage()
Parameters:
args - Provide an optional boolean if you want debugging information dumped to System.out.
Returns:
boolean True if went without exception, false otherwise

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object