com.raj.extensions
Class SendingMail

java.lang.Object
  |
  +--com.raj.extensions.SendingMail

public class SendingMail
extends java.lang.Object

A class to send mail messages by SMTP. This is a simple class that just opens a socket directly to the server and writes to it. You must provide the following data for the object:

These can be provided in a constructor or using the provided getter and setter methods. You can add extra headers using the getOtherHeaders() and setOtherHeaders() methods.

Author:
Rajnish Bhaskar

Constructor Summary
SendingMail()
           
SendingMail(boolean helo)
          some servers need the server name in initial handshaking
SendingMail(boolean helo, java.lang.String svr)
           
SendingMail(java.lang.String svr)
           
SendingMail(java.lang.String svr, int p)
           
SendingMail(java.lang.String svr, java.lang.String sndr, java.lang.String f, java.lang.String t)
           
SendingMail(java.lang.String svr, java.lang.String sndr, java.lang.String f, java.lang.String t, java.lang.String sub)
           
SendingMail(java.lang.String svr, java.lang.String sndr, java.lang.String f, java.lang.String t, java.lang.String sub, java.lang.String m, boolean hns)
          constructor that lets you set everything except the port
SendingMail(java.lang.String svr, java.lang.String sndr, java.lang.String f, java.lang.String t, java.lang.String sub, java.lang.String m, int p, boolean hns)
          constructor that lets you set everything in one go
 
Method Summary
 java.lang.String getFrom()
          get sender's email address
 boolean getHelo()
          get whether or not handshaking (HELO) needs server name
 java.lang.String getMessage()
          get the message text of the email
 java.lang.String getOtherHeaders()
          return the other headers, or null if there are none
 int getPort()
          return port number
 java.lang.String getSender()
          get the sender's name
 java.lang.String getServer()
          return server name as String
 java.lang.String getSubject()
          get subject of the email
 java.lang.String getTo()
          get receipient's email address
 java.lang.String send()
          Sends the message represented by this object and returns the replies from the server as a string.
 void setFrom(java.lang.String f)
          set sender's email address
 void setHelo(boolean h)
          set whether or not handshaking (HELO) needs server name
 void setMessage(java.lang.String m)
          set the message itself.
 void setOtherHeaders(java.lang.String h)
          set any extra mail headers, with multiple headers being separated by \n
 void setPort(int p)
          set port on the server
 void setSender(java.lang.String s)
          set sender's name
 void setServer(java.lang.String s)
          set server to s
 void setSubject(java.lang.String s)
          set subject of the email
 void setTo(java.lang.String t)
          set receipient's email address
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SendingMail

public SendingMail()

SendingMail

public SendingMail(boolean helo)
some servers need the server name in initial handshaking

Parameters:
helo - if true, sends the server name along with initial handshaking

SendingMail

public SendingMail(java.lang.String svr)

SendingMail

public SendingMail(boolean helo,
                   java.lang.String svr)

SendingMail

public SendingMail(java.lang.String svr,
                   int p)

SendingMail

public SendingMail(java.lang.String svr,
                   java.lang.String sndr,
                   java.lang.String f,
                   java.lang.String t)

SendingMail

public SendingMail(java.lang.String svr,
                   java.lang.String sndr,
                   java.lang.String f,
                   java.lang.String t,
                   java.lang.String sub)

SendingMail

public SendingMail(java.lang.String svr,
                   java.lang.String sndr,
                   java.lang.String f,
                   java.lang.String t,
                   java.lang.String sub,
                   java.lang.String m,
                   boolean hns)
constructor that lets you set everything except the port


SendingMail

public SendingMail(java.lang.String svr,
                   java.lang.String sndr,
                   java.lang.String f,
                   java.lang.String t,
                   java.lang.String sub,
                   java.lang.String m,
                   int p,
                   boolean hns)
constructor that lets you set everything in one go

Method Detail

setServer

public void setServer(java.lang.String s)
set server to s


getServer

public java.lang.String getServer()
return server name as String


setPort

public void setPort(int p)
set port on the server


getPort

public int getPort()
return port number


setSender

public void setSender(java.lang.String s)
set sender's name


getSender

public java.lang.String getSender()
get the sender's name


setFrom

public void setFrom(java.lang.String f)
set sender's email address


getFrom

public java.lang.String getFrom()
get sender's email address


setTo

public void setTo(java.lang.String t)
set receipient's email address


getTo

public java.lang.String getTo()
get receipient's email address


setSubject

public void setSubject(java.lang.String s)
set subject of the email


getSubject

public java.lang.String getSubject()
get subject of the email


setHelo

public void setHelo(boolean h)
set whether or not handshaking (HELO) needs server name


getHelo

public boolean getHelo()
get whether or not handshaking (HELO) needs server name


setMessage

public void setMessage(java.lang.String m)
set the message itself. This is a String, so can't be longer than the max length of a String object in Java (I'm not sure how long that this is


getMessage

public java.lang.String getMessage()
get the message text of the email


setOtherHeaders

public void setOtherHeaders(java.lang.String h)
set any extra mail headers, with multiple headers being separated by \n


getOtherHeaders

public java.lang.String getOtherHeaders()
return the other headers, or null if there are none


send

public java.lang.String send()
                      throws SendingMailException,
                             java.net.UnknownHostException,
                             java.io.IOException
Sends the message represented by this object and returns the replies from the server as a string.

Returns:
a String containing the replies from the server If not all the fields are filled in, a SendingMailException is thrown
Throws:
SendingMailException
java.net.UnknownHostException
java.io.IOException