Class SendMail
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- ptolemy.actor.lib.mail.SendMail
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class SendMail extends TypedAtomicActor
Upon firing, send email to the specified recipient. This actor uses the SMTP protocol and will prompt for a password upon being first invoked. The password is sent encrypted.By default, this actor will not actually send email, but will rather produce the formatted email on its output port. The reason for this is that sending email should be done with some hesitation, since it is easy with such an actor to create a flood of email that will have undesirable effects. To get the actor to actually send email, change the value of the reallySendMail parameter to true. Upon completion of an execution, reallySendMail will be set back to false (in the wrapup() method) to help prevent accidental duplicate mailings.
This actor requires the JavaMail 1.5 javax.mail.jar file be in the classpath.
To use this actor, download
javax.mail.jar
https://java.net/projects/javamail/pages/Home
and place it in$PTII/vendors/misc/javamail
. Below are the steps:cd $PTII/vendors/misc/javamail wget --no-check-certificate http://java.net/projects/javamail/downloads/download/javax.mail.jar cd $PTII ./configure
In Eclipse, you will then need to refresh the project.
If you are using Google as your smtp provider, then you may need to modify your Google account to Allow less secure apps to access your account.
This is because this actor does not support OAuth 2.0. Allow less secure apps to access accounts Frequently Asked Questions (FAQ) says:
What criteria is used to identify an application as being "less secure"?
Applications that rely on plain username/password authentication to access an account programmatically are considered less secure than those using modern day security standards such as OAuth 2.0.
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Edward A. Lee
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description FileParameter
attach
File to attach, if any.PortParameter
cc
Email address to copy on the message.Parameter
enableSSL
Enable the Secure Sockets Layer (SSL) protocol.PortParameter
from
Email address from which this is sent.PortParameter
message
The message to send.TypedIOPort
output
Output to which the formatted message is sent.PortParameter
password
Password port of the account.Parameter
reallySendMail
If true, then actually send the email.PortParameter
replyTo
The address to which replies should be directed.PortParameter
SMTPHostName
Host name for the send mail server.PortParameter
SMTPPort
Outgoing SMTP mail port.PortParameter
SMTPUserName
User name for the send mail server.PortParameter
subject
The subject line.PortParameter
to
Email address(es) to which this is sent.-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description SendMail(CompositeEntity container, java.lang.String name)
Construct an actor with the given container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeChanged(Attribute attribute)
React to a change in an attribute.boolean
postfire()
Update the parameters based on any available inputs and then send one email message.void
preinitialize()
Set up the properties for the SMTP protocol.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
attach
public FileParameter attach
File to attach, if any. By default, this is empty, which means to not attach any file.
-
cc
public PortParameter cc
Email address to copy on the message.
-
from
public PortParameter from
Email address from which this is sent.
-
message
public PortParameter message
The message to send. This defaults to an empty string.
-
output
public TypedIOPort output
Output to which the formatted message is sent. The type of this output is string.
-
password
public PortParameter password
Password port of the account.
-
replyTo
public PortParameter replyTo
The address to which replies should be directed. This is a comma-separated list that defaults to an empty string, which indicates that the reply should go to the address specified by from.
-
reallySendMail
public Parameter reallySendMail
If true, then actually send the email. This is a boolean that defaults to false, meaning that the message is only sent to the output port. This parameter will be set back to false in the wrapup() method, to help prevent duplicate mailings.
-
SMTPHostName
public PortParameter SMTPHostName
Host name for the send mail server.
-
SMTPPort
public PortParameter SMTPPort
Outgoing SMTP mail port.
-
SMTPUserName
public PortParameter SMTPUserName
User name for the send mail server.
-
enableSSL
public Parameter enableSSL
Enable the Secure Sockets Layer (SSL) protocol.
-
subject
public PortParameter subject
The subject line. This defaults to an empty string.
-
to
public PortParameter to
Email address(es) to which this is sent. This is a comma-separated list that defaults to "nobody1@nowhere.com, nobody2@nowhere.com".
-
-
Constructor Detail
-
SendMail
public SendMail(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct an actor with the given container and name.- Parameters:
container
- The container.name
- The name of this actor.- Throws:
IllegalActionException
- If the actor cannot be contained by the proposed container.NameDuplicationException
- If the container already has an actor with this name.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
React to a change in an attribute. This method is called by a contained attribute when its value changes. In this class, if the SMTP host or user name is changed, this method forgets the password.- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the change is not acceptable to this container (not thrown in this base class).
-
preinitialize
public void preinitialize() throws IllegalActionException
Set up the properties for the SMTP protocol.- Specified by:
preinitialize
in interfaceInitializable
- Overrides:
preinitialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the superclass throws it.
-
postfire
public boolean postfire() throws IllegalActionException
Update the parameters based on any available inputs and then send one email message.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- Returns:
- True if execution can continue into the next iteration.
- Throws:
IllegalActionException
- If any of several errors occur while attempting to send the message.
-
-