|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ipworks.Smtp
The SMTP class is used to send Internet mail using the SMTP protocol (the Internet mail standard).
The SMTP class implements a standard SMTP client as specified in RFC 821. It has a simple plug-and-play interface. It contains a number of properties like To , Subject , From , Cc , BCc , etc. that map directly to the internet mail message headers with the same name (RFC 822). The message text is set in MessageText and/or AttachedFile . Messages are sent by setting the Action property to 'Send Message'.
The class supports message delivery to multiple recipients through the To , Cc , and BCc properties. Simply specify the destination email addresses separated by commas.
The interface of the class is open-ended. New features, including MIME attachments can be supported by using the OtherHeaders property.
A number of events provide feedback during the operation of the class. The Transfer event is fired during message delivery to show the number of bytes delivered. The PITrail event traces the commands that are sent to the server and the respective replies.
Field Summary | |
static int |
a_Connect
|
static int |
a_Disconnect
|
static int |
a_Expand
|
static int |
a_Idle
|
static int |
a_ResetHeaders
|
static int |
a_Send
|
static int |
a_SendToTerminalAndEmail
|
static int |
a_SendToTerminalOnly
|
static int |
a_SendToTerminalOrEmail
|
static int |
a_Verify
|
Constructor Summary | |
Smtp()
|
Method Summary | |
void |
addSmtpEventListener(SmtpEventListener l)
|
void |
fireEndTransfer()
Fired when the message text completes transferring. |
void |
fireError(int errorCode,
java.lang.String description)
Information about errors during data delivery. |
void |
fireExpand(java.lang.String address)
Fired for every email address returned by the server when Action is set to Expand . |
void |
firePITrail(int direction,
java.lang.String message)
Traces the commands sent to the mail server, and the respective replies. |
void |
fireStartTransfer()
Fired when the message text starts transferring. |
void |
fireTransfer(int bytesTransferred)
Fired while the message text gets transferred to MailServer . |
int |
getAction()
An action code for the component. |
java.lang.String |
getAttachedFile()
A file to append to MessageText when sending mail. |
java.lang.String |
getBCc()
A comma separated list of addresses for blind carbon copies (optional). |
java.lang.String |
getCc()
A comma separated list of addresses for carbon copies (optional). |
java.lang.String |
getDate()
The Date of the mail message (optional). |
java.lang.String |
getFrom()
The email address of the sender (required). |
java.lang.String |
getHello()
The argument for HELO (herald) command to the server (defaults to local host name). |
java.lang.String |
getLastReply()
The last reply from the server. |
java.lang.String |
getLocalHost()
The name of the local host. |
int |
getMailPort()
The server port for SMTP (default 25). |
java.lang.String |
getMailServer()
The name or address of a mail server (mail relay). |
int |
getMaxHeaderLength()
Maximum length for headers to avoid line folding (default 80). |
java.lang.String |
getMessageText()
The full text of the message to send (without headers). |
java.lang.String |
getOtherHeaders()
An RFC 822 compliant string consisting of extra headers. |
java.lang.String |
getReplyTo()
A mail address to reply to (optional). |
java.lang.String |
getSubject()
The subject of the mail message (optional). |
java.lang.String |
getTo()
A comma separated list of addresses for destinations (required). |
boolean |
isAllowExtensions()
A switch allowing the component to use ESMTP features (SMTP extensions). |
void |
removeSmtpEventListener(SmtpEventListener l)
|
void |
setAction(int action)
An action code for the component. |
void |
setAllowExtensions(boolean allowExtensions)
A switch allowing the component to use ESMTP features (SMTP extensions). |
void |
setAttachedFile(java.lang.String attachedFile)
A file to append to MessageText when sending mail. |
void |
setBCc(java.lang.String BCc)
A comma separated list of addresses for blind carbon copies (optional). |
void |
setCc(java.lang.String cc)
A comma separated list of addresses for carbon copies (optional). |
void |
setCommand(java.lang.String command)
Can be used to send additional commands directly to the SMTP server. |
void |
setDate(java.lang.String date)
The Date of the mail message (optional). |
void |
setFrom(java.lang.String from)
The email address of the sender (required). |
void |
setHello(java.lang.String hello)
The argument for HELO (herald) command to the server (defaults to local host name). |
void |
setMailPort(int mailPort)
The server port for SMTP (default 25). |
void |
setMailServer(java.lang.String mailServer)
The name or address of a mail server (mail relay). |
void |
setMaxHeaderLength(int maxHeaderLength)
Maximum length for headers to avoid line folding (default 80). |
void |
setMessageText(java.lang.String messageText)
The full text of the message to send (without headers). |
void |
setOtherHeaders(java.lang.String otherHeaders)
An RFC 822 compliant string consisting of extra headers. |
void |
setReplyTo(java.lang.String replyTo)
A mail address to reply to (optional). |
void |
setSubject(java.lang.String subject)
The subject of the mail message (optional). |
void |
setTo(java.lang.String to)
A comma separated list of addresses for destinations (required). |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int a_Idle
public static final int a_Connect
public static final int a_Disconnect
public static final int a_Send
public static final int a_ResetHeaders
public static final int a_Expand
public static final int a_Verify
public static final int a_SendToTerminalAndEmail
public static final int a_SendToTerminalOrEmail
public static final int a_SendToTerminalOnly
Constructor Detail |
public Smtp()
Method Detail |
public int getAction()
The following are the possible values for the Action property and the corresponding descriptions:
public void setAction(int action) throws IPWorksException
The following are the possible values for the Action property and the corresponding descriptions:
public boolean isAllowExtensions()
The property is true by default but may be disabled if it's known in advance that the MailServer doesn't support SMTP extensions.
public void setAllowExtensions(boolean allowExtensions) throws IPWorksException
The property is true by default but may be disabled if it's known in advance that the MailServer doesn't support SMTP extensions.
public java.lang.String getAttachedFile()
It is advisable that the text contained in the file be a collection of lines with lengths less than or equal to 80 bytes separated by CRLF ("\\r\\n") . The text in the message lines must contain 7-bit characters so that the message can be successfully pass through the multitude of mail systems on the Internet.
The class automatically escapes lines that start with a "." by adding another as specified in RFC 822. The message text is unescaped by the receiving agent, so the process is fully transparent.
public void setAttachedFile(java.lang.String attachedFile) throws IPWorksException
It is advisable that the text contained in the file be a collection of lines with lengths less than or equal to 80 bytes separated by CRLF ("\\r\\n") . The text in the message lines must contain 7-bit characters so that the message can be successfully pass through the multitude of mail systems on the Internet.
The class automatically escapes lines that start with a "." by adding another as specified in RFC 822. The message text is unescaped by the receiving agent, so the process is fully transparent.
public java.lang.String getBCc()
The class will return an error if the MailServer returns an error code about any email address specified in To or Cc but it will only fire an Error event if the same happens with an email address specified in BCc .
If the resulting BCc header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public void setBCc(java.lang.String BCc) throws IPWorksException
The class will return an error if the MailServer returns an error code about any email address specified in To or Cc but it will only fire an Error event if the same happens with an email address specified in BCc .
If the resulting BCc header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public java.lang.String getCc()
The class will return an error if the MailServer returns an error code about any email address specified in To or Cc but it will only fire an Error event if the same happens with an email address specified in BCc .
If the resulting Cc header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public void setCc(java.lang.String cc) throws IPWorksException
The class will return an error if the MailServer returns an error code about any email address specified in To or Cc but it will only fire an Error event if the same happens with an email address specified in BCc .
If the resulting Cc header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public void setCommand(java.lang.String command) throws IPWorksException
public java.lang.String getDate()
If the resulting Date header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
RFC 822 contains detailed date format specifications. An example of a valid date is "Fri, 1 Mar 96 21:24:52 EST".
public void setDate(java.lang.String date) throws IPWorksException
If the resulting Date header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
RFC 822 contains detailed date format specifications. An example of a valid date is "Fri, 1 Mar 96 21:24:52 EST".
public java.lang.String getFrom()
If the resulting From header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public void setFrom(java.lang.String from) throws IPWorksException
If the resulting From header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public java.lang.String getHello()
If AllowExtensions is true the EHLO command will be sent instead of the HELO command.
public void setHello(java.lang.String hello) throws IPWorksException
If AllowExtensions is true the EHLO command will be sent instead of the HELO command.
public java.lang.String getLastReply()
public java.lang.String getLocalHost()
If the class is connected, the LocalHost property shows the IP address of the interface through which the connection is made in internet dotted format (aaa.bbb.ccc.ddd). In most cases, this is the address of the local host, except for multihomed hosts (machines with more than one IP interface).
public int getMailPort()
public void setMailPort(int mailPort) throws IPWorksException
public java.lang.String getMailServer()
The current version of the class does not provide a default value for the mail relay. You must provide a host name yourself. Generally, any internet host with an SMTP server will suffice (a UNIX host for example), but it is preferable to select a MailServer that is close to the machine sending mail.
If the MailServer property is set to a Domain Name, a DNS request is initiated and upon successful termination of the request, the MailServer property is set to the corresponding address. If the search is not successful, an error is returned.
public void setMailServer(java.lang.String mailServer) throws IPWorksException
The current version of the class does not provide a default value for the mail relay. You must provide a host name yourself. Generally, any internet host with an SMTP server will suffice (a UNIX host for example), but it is preferable to select a MailServer that is close to the machine sending mail.
If the MailServer property is set to a Domain Name, a DNS request is initiated and upon successful termination of the request, the MailServer property is set to the corresponding address. If the search is not successful, an error is returned.
public int getMaxHeaderLength()
It is generally a good idea to use a MaxHeaderLength of less than 100 bytes, although different mail relays and mail servers have different requirements for header lengths.
public void setMaxHeaderLength(int maxHeaderLength) throws IPWorksException
It is generally a good idea to use a MaxHeaderLength of less than 100 bytes, although different mail relays and mail servers have different requirements for header lengths.
public java.lang.String getMessageText()
It is advisable that the text contained in this property be a collection of lines with lengths less than or equal to 80 bytes separated by CRLF ("\\r\\n"). The text in the message lines must contain 7-bit characters so that the message can be successfully pass through the multitude of mail systems on the Internet.
The class automatically escapes lines that start with a "." by adding another as specified in RFC 822. The message text is unescaped by the receiving agent, so the process is fully transparent.
public void setMessageText(java.lang.String messageText) throws IPWorksException
It is advisable that the text contained in this property be a collection of lines with lengths less than or equal to 80 bytes separated by CRLF ("\\r\\n"). The text in the message lines must contain 7-bit characters so that the message can be successfully pass through the multitude of mail systems on the Internet.
The class automatically escapes lines that start with a "." by adding another as specified in RFC 822. The message text is unescaped by the receiving agent, so the process is fully transparent.
public java.lang.String getOtherHeaders()
The headers must of the format "header: value" as specified in RFC 822. Header lines should be separated by CRLF ("\\r\\n").
Use this property with caution. If OtherHeaders contains invalid headers, message delivery might not be successful.
The OtherHeaders property is useful for extending the functionality of the class. A good example is delivery of MIME encoded messages.
public void setOtherHeaders(java.lang.String otherHeaders) throws IPWorksException
The headers must of the format "header: value" as specified in RFC 822. Header lines should be separated by CRLF ("\\r\\n").
Use this property with caution. If OtherHeaders contains invalid headers, message delivery might not be successful.
The OtherHeaders property is useful for extending the functionality of the class. A good example is delivery of MIME encoded messages.
public java.lang.String getReplyTo()
If the resulting Reply-To header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public void setReplyTo(java.lang.String replyTo) throws IPWorksException
If the resulting Reply-To header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public java.lang.String getSubject()
If the resulting Subject header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public void setSubject(java.lang.String subject) throws IPWorksException
If the resulting Subject header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public java.lang.String getTo()
The class will return an error if the MailServer returns an error code about any email address specified in To or Cc but it will only fire an Error event if the same happens with an email address specified in BCc .
If the resulting To header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public void setTo(java.lang.String to) throws IPWorksException
The class will return an error if the MailServer returns an error code about any email address specified in To or Cc but it will only fire an Error event if the same happens with an email address specified in BCc .
If the resulting To header is longer than MaxHeaderLength , then it is folded according to RFC 822 specifications.
public void fireEndTransfer()
SmtpEndTransferEvent
public void fireError(int errorCode, java.lang.String description)
SmtpErrorEvent
public void fireExpand(java.lang.String address)
SmtpExpandEvent
public void firePITrail(int direction, java.lang.String message)
SmtpPITrailEvent
public void fireStartTransfer()
SmtpStartTransferEvent
public void fireTransfer(int bytesTransferred)
SmtpTransferEvent
public void addSmtpEventListener(SmtpEventListener l) throws java.util.TooManyListenersException
public void removeSmtpEventListener(SmtpEventListener l)
|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |