AdobeBridgeCS5SDK

Class BackgroundEmailer

Object
   |
   +--BackgroundEmailer

class BackgroundEmailer


Sample using the Socket object to send email with attachments as a background (scheduled) task.

Usage

You must edit the mailserver settings within this code; the code as shipped does not provide any default values for these settings and if you do not edit these settings in the code (see "NOTE" below), then the code will not run correctly.
  1. Customize the email settings in the code to match your mail system and user accounts; look for NOTE below.
  2. Execute the snippet in the ExtendScript Toolkit, with Bridge as the target (see Readme.txt)
  3. You should find this creates a context-sensitive menu item on selected file thumbnails.
  4. In the Content pane of Bridge, select one or more thumbnails for the files to send.
  5. Right click in Windows or Ctrl-click in Mac OS to invoke the context menu
  6. Choose the menu item "SDK BackgroundEmailer: Send by Email"
  7. Inspect the JavaScript console for confirmation of the email being sent.
  8. Check your email client for the arrival of an email with attached files

Description

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:

Defined in BackgroundEmailer.jsx


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

requiredContext

String requiredContext

b64Chars

<static> String b64Chars

boundary

<static> String boundary

contents

<static> String contents

encodeTaskID

<static> Number encodeTaskID

finishedAttachment

<static> Boolean finishedAttachment

isRunning

<static> String isRunning

mailServerName

<static> String mailServerName

password

<static> Socket password

POP

<static> int POP

recipient

<static> String recipient

sender

<static> String sender

SMTP

<static> int SMTP

socket

<static> Socket socket

startAttach

<static> Boolean startAttach

subject

<static> String subject

Thumbnails

<static> Array of Thumbnail Thumbnails

username

<static> String username

Constructor Detail

BackgroundEmailer

BackgroundEmailer()

Method Detail

canRun

Boolean canRun()

run

Boolean run()

authorise

<static> void authorise()

buildMessageBody

<static> void buildMessageBody()

close

<static> void close()

connect

<static> Boolean connect(host, port)

doCommand

<static> Boolean doCommand(cmd, type)

encodeString

<static> String encodeString(binaryString)

finishEmail

<static> void finishEmail()

nextChunk

<static> String nextChunk()

send

<static> void send()

sendData

<static> Boolean sendData()

AdobeBridgeCS5SDK

http://www.adobe.com/devnet/bridge
Documentation generated by JSDoc on Tue Apr 27 10:21:34 2010