public class SmtpMailer
extends java.lang.Object
Constructor and Description |
---|
SmtpMailer()
Creates a new simple SmtpMailer.
|
SmtpMailer(java.lang.String host)
Creates a new simple SmtpMailer from a host name.
|
Modifier and Type | Method and Description |
---|---|
void |
addAdditionalField(java.lang.String line)
Sets any additional field according to RFC822.
|
void |
addBcc(java.lang.String realName,
java.lang.String emailAddress)
Sets the Bcc field.
|
void |
addCc(java.lang.String realName,
java.lang.String emailAddress)
Sets the Cc field.
|
void |
addText(java.lang.String text)
Adds text to message body of this EMail.
|
void |
addTo(java.lang.String realName,
java.lang.String emailAddress)
Sets the To field.
|
protected boolean |
checkResponse(int expected)
Checks the response from the smtpd.
|
protected boolean |
send(java.lang.String message,
java.io.PrintWriter writer,
int expected)
Prints a string using the specified PrintWriter.
|
protected boolean |
sendCommands(java.io.PrintWriter writer)
Sends the SMTP commands to the smtpd.
|
boolean |
sendMail()
Send the mail that was just created.
|
void |
setDebug(boolean on)
Switches debugging output on or off.
|
void |
setFrom(java.lang.String realName,
java.lang.String emailAddress)
Sets the From field.
|
void |
setLineSeparator(java.lang.String lineSeparator)
Sets the line separator to be used (Default: System default).
|
void |
setReplyTo(java.lang.String realName,
java.lang.String emailAddress)
Sets the Reply-To field.
|
void |
setSender(java.lang.String realName,
java.lang.String emailAddress)
Sets the Sender field.
|
void |
setSubject(java.lang.String subject)
Sets the Subject.
|
void |
setText(java.lang.String text)
Sets the message body of this EMail.
|
void |
setVerify(boolean on)
If verify is switched on (default) SmtpMailer checks every response code
from smtpd and compares it to the expected value.
|
java.lang.String |
toString()
Returns a string representation of this SmtpMailer.
|
protected void |
writeBody(java.io.PrintWriter writer)
Uses this PrintWriter to print the message body.
|
protected void |
writeHeaders(java.io.PrintWriter writer)
Uses this PrintWriter to print the headers.
|
public SmtpMailer(java.lang.String host)
host
- the host with the SMTP demonpublic SmtpMailer()
public void setFrom(java.lang.String realName, java.lang.String emailAddress)
realName
- the real name of the senderemailAddress
- the email address of the senderpublic void setSender(java.lang.String realName, java.lang.String emailAddress)
realName
- the real name of the senderemailAddress
- the email address of the senderpublic void setReplyTo(java.lang.String realName, java.lang.String emailAddress)
realName
- the real name of one receiveremailAddress
- the email address of one receiverpublic void setVerify(boolean on)
on
- true to switch verification onpublic void setDebug(boolean on)
on
- true switches debugging onpublic void addTo(java.lang.String realName, java.lang.String emailAddress)
realName
- the real name of one receiveremailAddress
- the email address of one receiverpublic void addCc(java.lang.String realName, java.lang.String emailAddress)
realName
- the real name of one receiveremailAddress
- the email address of one receiverpublic void addBcc(java.lang.String realName, java.lang.String emailAddress)
realName
- the real name of one receiveremailAddress
- the email address of one receiverpublic void addAdditionalField(java.lang.String line)
line
- a complete linepublic void setSubject(java.lang.String subject)
subject
- the subjectpublic void setText(java.lang.String text)
text
- the text to be appendedpublic void addText(java.lang.String text)
text
- the text to be appendedprotected boolean checkResponse(int expected) throws SmtpException
expected
- the expected response codeSmtpException
- if there was an error while reading the responseprotected boolean send(java.lang.String message, java.io.PrintWriter writer, int expected) throws SmtpException
message
- the string to printwriter
- the PrintWriter to useexpected
- the expected response code from the serverSmtpException
- if there was an error while sending this stringprotected boolean sendCommands(java.io.PrintWriter writer) throws SmtpException
writer
- the PrintWriter to useSmtpException
- if there was an error while sending the commandsprotected void writeHeaders(java.io.PrintWriter writer)
writer
- the PrintWriter for printing the headersprotected void writeBody(java.io.PrintWriter writer)
writer
- the PrintWriter for printing the message bodypublic boolean sendMail() throws SmtpException
SmtpException
- if there is a problem while sending the EMailpublic void setLineSeparator(java.lang.String lineSeparator)
lineSeparator
- the line separator to be usedpublic java.lang.String toString()
toString
in class java.lang.Object