All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class mkgray.adopted.SMTPmail

java.lang.Object
   |
   +----mkgray.adopted.SMTPmail

public class SMTPmail
extends Object
*** New in Version 2: *** - Stream Input to Mailobject - Add MIME Attachements to mail object SMTP Mailing Object. Allows sending mails to any smtpd. Possibilities to set varios detail information. Also, there is detailed exception handling for paranoids. Implements complete SMTP handshake.
Following Mail structure generated to the smtp server is something like:
   HELO  
   MAIL FROM: 
   RCPT TO: 
   DATA
     From: name_of_from 
     Sender: name_of_sender 
     To: name_of_to 
     Reply-To: name_of_replyto 
     cc: name_of_cc 
     cc: name_of_cc      (...there can be many cc's...)
     bcc: name_of_bcc 
     bcc: name_of_bcc      (...there can be many bcc's...)
       (...one delimiting empty line ...)
     Text_of_mail
     . (the final dot)
   QUIT
 
For example:
  ...
    try {
      SMTPmail mail = new SMTPmail("whateverhost.wherever.com");
      mail.setFrom("Bob Schulze", "bob@sleepers.com");      
                                 // Brackets are not neccesary here
      mail.setTo("Whoever listens", "listener@taxoffice.gov");
                                 // Subsequent calls will append to the receivers' list
      mail.setSubject("Found something...");
      mail.addReplyTo("White House","president@whitehouse.gov")  
      mail.addFile("/home/incometax.txt");
      mail.sendMail();
    } catch (SMTPException e) {
      System.out.println("Something went wrong with your income tax: " + e.getMessage());
    }
 ...
 
Check also: RFC822 (Message Format)
Check also: RFC821 (SMTP Protocol)
Check also: RFC1891..1894 (ESMTP Extensions)


Constructor Index

 o SMTPmail()
Creates a Mail Object that does the whole thing.
 o SMTPmail(String)
Creates a Mail Object that does the whole thing.

Method Index

 o addAny(String)
Sets any additional field according to RFC822 like:
    resent-date =  "Resent-Date" ":"   date-time     
    "Resent-To"   ":" 1#address     
    "Resent-cc"   ":" 1#address      
    "Resent-bcc"  ":"  #address
    "Message-ID"        ":"   msg-id ( msg-id      =  "<" addr-spec ">" )
    "Resent-Message-ID" ":"   msg-id
    "In-Reply-To"       ":"   *(phrase / msg-id)
    "References"        ":"   *(phrase / msg-id)
    "Keywords"          ":"   #phrase
    "Subject"           ":"   *text
    "Comments"          ":"   *text
    "Encrypted"         ":"   1#2word
    extension-field           Head with "X-"
 
check also: RFC822
Subsequent calls will override.
 o addBcc(String, String)
Sets the BCC Section.
 o addCc(String, String)
Sets the CC Section.
 o addFile(String)
Adds the contents of file to your mail.
 o addReplyTo(String, String)
Sets the Reply-To Adresses.
 o addText(String)
Adds some contents to your mail.
 o addTo(String, String)
Sets the To Section.
 o sendMail()
Send the mail that was specified using the other methods
 o setDebug(boolean)
With debug == true, jSMTPmail will check print out each handshake with smtpd.
 o setFrom(String, String)
Sets the From Section.
 o setSubject(String)
Sets the Subject.
 o setTimeOut(int)
Timeout sets the time, that jSMTPmail waits for the hosts response until it fires a Exception.
 o setVerify(boolean)
With verify == true, jSMTPmail will check each response from smtpd carefully.

Constructors

 o SMTPmail
 public SMTPmail(String host)
Creates a Mail Object that does the whole thing.

Parameters:
host - The Host name known to the Runtime environment. Use getCodeBase() to find out.
Returns:
The object
 o SMTPmail
 public SMTPmail()
Creates a Mail Object that does the whole thing. It will try to connect to the local host's smtpd.

Returns:
The object

Methods

 o setFrom
 public void setFrom(String real_name,
                     String address)
Sets the From Section. Subsequent calls will override.

Parameters:
real_name - The real name of the User
address - The address of the User
Returns:
Nothing
 o setVerify
 public void setVerify(boolean how)
With verify == true, jSMTPmail will check each response from smtpd carefully. Strongly recommended. Otherwise, smtpd might miss some information and will finally fail delivering the mail. True by default.

Parameters:
how - true or false
Returns:
Nothing
See Also:
setTimeOut
 o setDebug
 public void setDebug(boolean how)
With debug == true, jSMTPmail will check print out each handshake with smtpd. Useful for debugging or learning. Print out happens only when sendMail is activated. False by default.

Parameters:
how - true or false
Returns:
Nothing
 o setTimeOut
 public void setTimeOut(int steps)
Timeout sets the time, that jSMTPmail waits for the hosts response until it fires a Exception. Use a bigger value on slow hosts. Is set to 20 time 200 ms (4s) by default

Parameters:
steps - time units of 200 ms, e.g. 20 means 4 seconds
Returns:
Nothing
 o addTo
 public void addTo(String real_name,
                   String address)
Sets the To Section. Can be called multiple times in order to Send mail to varios recipients.

Parameters:
real_name - The real name of the User
address - The address of the User
Returns:
Nothing
 o addCc
 public void addCc(String real_name,
                   String address)
Sets the CC Section. Can be called multiple times in order to Send mail to varios recipients.

Parameters:
real_name - The real name of the User
address - The address of the User
Returns:
Nothing
 o addBcc
 public void addBcc(String real_name,
                    String address)
Sets the BCC Section. Can be called multiple times in order to Send mail to varios recipients.

Parameters:
real_name - The real name of the User
address - The address of the User
Returns:
Nothing
 o addReplyTo
 public void addReplyTo(String real_name,
                        String address)
Sets the Reply-To Adresses. Can be called multiple times ??

Parameters:
real_name - The real name of the User
address - The address of the User
Returns:
Nothing
 o addAny
 public void addAny(String complete_line)
Sets any additional field according to RFC822 like:
    resent-date =  "Resent-Date" ":"   date-time     
    "Resent-To"   ":" 1#address     
    "Resent-cc"   ":" 1#address      
    "Resent-bcc"  ":"  #address
    "Message-ID"        ":"   msg-id ( msg-id      =  "<" addr-spec ">" )
    "Resent-Message-ID" ":"   msg-id
    "In-Reply-To"       ":"   *(phrase / msg-id)
    "References"        ":"   *(phrase / msg-id)
    "Keywords"          ":"   #phrase
    "Subject"           ":"   *text
    "Comments"          ":"   *text
    "Encrypted"         ":"   1#2word
    extension-field           Head with "X-"
 
check also: RFC822
Subsequent calls will override. Note that many email-Readers do ignore this part.

Parameters:
complete_line - The complete line that will be sent. You are responsible for its correctness.
Returns:
Nothing
 o setSubject
 public void setSubject(String subject)
Sets the Subject. will override when called multiple times. Reset it by calling it with an empty string.

Parameters:
subject - The Subject line
Returns:
Nothing
 o addText
 public void addText(String text)
Adds some contents to your mail. No formatting on it is done.

Parameters:
text - Text to append to the mail.
Returns:
Nothing
 o addFile
 public void addFile(String filename) throws SMTPException
Adds the contents of file to your mail. No formatting on it is done (Also not linefeeds!)

Parameters:
text - Text File to append to the mail.
Returns:
Nothing
 o sendMail
 public void sendMail() throws SMTPException
Send the mail that was specified using the other methods


All Packages  Class Hierarchy  This Package  Previous  Next  Index