|
AdobeBridgeCS5SDK | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object | +--BackgroundEmailer
Sample using the Socket object to send email with attachments as a background (scheduled) task.
This example uses the Socket object to send an email with multiple attachments, uing a scheduled task to perform encoding and send the data in the background. It sends just one email message at a time. Attachments are sent as binary data.
This example schedules a task to encode the data into Base64 encoding and write to the SMTP server as a background task, which does not block the Bridge main thread. The Bridge browser functions normally while the email and files are being sent. Static properties provide operation status updates within the scheduleTask() call.
When the send() method is called, the mail headers are written to the socket and a task named sendData() is scheduled to run and to repeat every 10 milliseconds. Whilst the task is in operation, a file to be attached is read as a binary string, encoded and written to the socket in chunks at a time. When the last chunk of the last file has been transmitted, the task is cancelled and the socket is closed.
You should be aware that this sample is a demonstration of technique; it may not run as expected with all mail servers, and it is not intended as a robust mail client.
For a blocking example, which might be suitable when sending smaller files as attachments, see BasicEmailer.jsx.
See:
Field Summary | |
String |
requiredContext
The context in which this snippet can run. |
<static> String |
b64Chars
The 64 characters used to encode the files to Base64. |
<static> String |
boundary
The boundary marker for attachments. |
<static> String |
contents
The binary contents of a file to be attached to the email. |
<static> Number |
encodeTaskID
The ID of the scheduled task that will encode and transmit data, needed to cancel the task after it has finished. |
<static> Boolean |
finishedAttachment
Flag that indicates when an attachment has been transmitted. |
<static> String |
isRunning
Flag that indicates whether or not an email operation is underway |
<static> String |
mailServerName
The host address for the mail server, for example mail.adomainname.com - NOTE: You must customize this with your own mailserver. |
<static> Socket |
password
The password for the username - NOTE: You must customize this with your own password for your (POP3) mail server. |
<static> int |
POP
The port number for the POP server, for example port 110 - NOTE: You may want to customize this for your system. |
<static> String |
recipient
The address the email will be sent to, the receiver of the email - NOTE: You must customize this with your own target recipient. |
<static> String |
sender
The senders email address, for example testemail |
<static> int |
SMTP
The port number for the SMTP server, for example port 25 - NOTE: You may want to customize this for your system. |
<static> Socket |
socket
The Socket object that this object uses to write to the wire. |
<static> Boolean |
startAttach
Flag that indicates when we are at the start of the process of attaching a new file. |
<static> String |
subject
The subject of the email. |
<static> Array of Thumbnail |
Thumbnails
The selected thumbnails for the files to be attached. |
<static> String |
username
The username, not necessarily the senders email, to authorize with, for example testemail |
Constructor Summary | |
BackgroundEmailer()
|
Method Summary | |
Boolean
|
canRun()
Determines whether snippet can be run given current context. |
Boolean
|
run()
Functional part of this snippet. |
<static> void
|
authorise()
Authorizes a username against POP3. |
<static> void
|
buildMessageBody()
Constructs a simple message for the body of the email showing which files are attached |
<static> void
|
close()
Close the socket that was used to transmit data |
<static> Boolean
|
connect(host, port)
Attempts to open a socket and connect to a given host and port. |
<static> Boolean
|
doCommand(cmd, type)
Executes an SMTP or a POP command. |
<static> String
|
encodeString(binaryString)
Accepts a string representing a binary file and encodes the string to base64. |
<static> void
|
finishEmail()
Ends the transmission; writes the last part of the boundary, sends the necessary SMTP commands and closes the socket. |
<static> String
|
nextChunk()
Get the next chunk of data from the binary contents of the current file that is to be attached to the email |
<static> void
|
send()
Sends the email and attachments by connecting to the server and authorizing via POP. |
<static> Boolean
|
sendData()
This is the task to send the attachment data, which is scheduled to run by the BackgroundEmailer.send() method. |
Field Detail |
String requiredContext
<static> String b64Chars
<static> String boundary
<static> String contents
<static> Number encodeTaskID
<static> Boolean finishedAttachment
<static> String isRunning
<static> String mailServerName
<static> Socket password
<static> int POP
<static> String recipient
<static> String sender
<static> int SMTP
<static> Socket socket
<static> Boolean startAttach
<static> String subject
<static> Array of Thumbnail Thumbnails
<static> String username
Constructor Detail |
BackgroundEmailer()
Method Detail |
Boolean canRun()
Boolean run()
<static> void authorise()
<static> void buildMessageBody()
<static> void close()
<static> Boolean connect(host, port)
host
- The server host name string.
port
- The port number, an integer.
<static> Boolean doCommand(cmd, type)
cmd
- The command to be written to the socket
type
- One of 'pop' or 'smtp'
<static> String encodeString(binaryString)
binaryString
- The string to encode
<static> void finishEmail()
<static> String nextChunk()
<static> void send()
Writes the mail headers to the socket, then schedules a task that will cause the data to be written in chunks to the socket. If there are any attachments to be sent, the task encodes them into Base64 and writes them to the socket.
<static> Boolean sendData()
|
AdobeBridgeCS5SDK | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |