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)
-
SMTPmail()
- Creates a Mail Object that does the whole thing.
-
SMTPmail(String)
- Creates a Mail Object that does the whole thing.
-
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.
-
addBcc(String, String)
- Sets the BCC Section.
-
addCc(String, String)
- Sets the CC Section.
-
addFile(String)
- Adds the contents of file to your mail.
-
addReplyTo(String, String)
- Sets the Reply-To Adresses.
-
addText(String)
- Adds some contents to your mail.
-
addTo(String, String)
- Sets the To Section.
-
sendMail()
-
Send the mail that was specified using the other methods
-
setDebug(boolean)
- With debug == true, jSMTPmail will check print out each handshake with smtpd.
-
setFrom(String, String)
- Sets the From Section.
-
setSubject(String)
- Sets the Subject.
-
setTimeOut(int)
- Timeout sets the time, that jSMTPmail waits for the hosts response until it fires a Exception.
-
setVerify(boolean)
- With verify == true, jSMTPmail will check each response from smtpd carefully.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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