Class MailSender
- java.lang.Object
-
- nl.nn.adapterframework.senders.SenderBase
-
- nl.nn.adapterframework.senders.SenderWithParametersBase
-
- nl.nn.adapterframework.senders.MailSenderBase
-
- nl.nn.adapterframework.senders.MailSender
-
- All Implemented Interfaces:
IConfigurable
,IConfigurationAware
,INamedObject
,IScopeProvider
,ISender
,ISenderWithParameters
,IWithParameters
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
@Category("Advanced") public class MailSender extends MailSenderBase
sender
that sends a mail specified by an XML message.Sample email.xml:
<email> <recipients> <recipient type="to">***@hotmail.com</recipient> <recipient type="cc">***@gmail.com</recipient> </recipients> <from name="*** ***">***@yahoo.com</from> <subject>This is the subject</subject> <threadTopic>subject</threadTopic> <message>This is the message</message> <messageType>text/plain</messageType><!-- Optional --> <messageBase64>false</messageBase64><!-- Optional --> <charset>UTF-8</charset><!-- Optional --> <attachments> <attachment name="filename1.txt">This is the first attachment</attachment> <attachment name="filename2.pdf" base64="true">JVBERi0xLjQKCjIgMCBvYmoKPDwvVHlwZS9YT2JqZWN0L1N1YnR5cGUvSW1...vSW5mbyA5IDAgUgo+PgpzdGFydHhyZWYKMzQxNDY2CiUlRU9GCg==</attachment> <attachment name="filename3.pdf" url="file:/c:/filename3.pdf"/> <attachment name="filename4.pdf" sessionKey="fileContent"/> </attachments><!-- Optional --> </email>
Notice: the XML message must be valid XML. Therefore, especially the message element must be plain text or be wrapped as CDATA. Example:
<message><![CDATA[<h1>This is a HtmlMessage</h1>]]></message>
The
sessionKey
attribute for attachment can contain an inputstream or a string. Other types are not supported at this moment.The attribute order for attachments is as follows:
- sessionKey
- url
- value of the attachment element
The
base64
attribute is only used when the value of the PipeLineSession variablesessionKey
is a String object or when the value of the attachment element is used. Ifbase64=true
then the value will be decoded before it's used.Compilation and Deployment Note: mail.jar (v1.2) and activation.jar must appear BEFORE j2ee.jar. Otherwise errors like the following might occur:
NoClassDefFoundException: com/sun/mail/util/MailDateFormat
- Author:
- Johan Verrips, Gerrit van Brakel
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
MailSender.MailSession
-
Nested classes/interfaces inherited from class nl.nn.adapterframework.senders.MailSenderBase
MailSenderBase.EMail, MailSenderBase.MailAttachmentBase<T>, MailSenderBase.MailAttachmentStream, MailSenderBase.MailSessionBase
-
-
Field Summary
-
Fields inherited from class nl.nn.adapterframework.senders.SenderWithParametersBase
parameterNamesMustBeUnique, paramList
-
Fields inherited from class nl.nn.adapterframework.senders.SenderBase
log
-
-
Constructor Summary
Constructors Constructor Description MailSender()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure()
configure()
is called once at startup of the framework in the configure method of the owner of this sender.protected MailSender.MailSession
createMailSession()
protected jakarta.mail.Session
createSession()
Create the session during runtimeString
getSmtpHost()
int
getSmtpPort()
void
open()
Create a session to validate connectivityString
sendEmail(MailSenderBase.MailSessionBase mailSession)
void
setSmtpHost(String newSmtpHost)
Name of the SMTP-host by which the messages are to be sendvoid
setSmtpPort(int newSmtpPort)
Port of the SMTP-host by which the messages are to be send-
Methods inherited from class nl.nn.adapterframework.senders.MailSenderBase
extract, getAuthAlias, getBounceAddress, getCredentialFactory, getDefaultAttachmentName, getDefaultFrom, getDefaultMessageType, getDefaultSubject, getDomainWhitelist, getPassword, getTimeout, getUserId, isDefaultMessageBase64, isSynchronous, sendMessage, setAuthAlias, setBounceAddress, setDefaultAttachmentName, setDefaultFrom, setDefaultMessageBase64, setDefaultMessageType, setDefaultSubject, setDomainWhitelist, setPassword, setTimeout, setUserId
-
Methods inherited from class nl.nn.adapterframework.senders.SenderWithParametersBase
addParameter, checkStringAttributeOrParameter, consumesSessionVariable, getParameterList, getParameterOverriddenAttributeValue, getParameterOverriddenAttributeValue, getParameterValueList
-
Methods inherited from class nl.nn.adapterframework.senders.SenderBase
close, createBean, getApplicationContext, getConfigurationClassLoader, getLogPrefix, getName, setApplicationContext, setName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContext
-
Methods inherited from interface nl.nn.adapterframework.core.IConfigurationAware
getApplicationContext, getName
-
Methods inherited from interface nl.nn.adapterframework.core.INamedObject
getName, setName
-
Methods inherited from interface nl.nn.adapterframework.core.IScopeProvider
getConfigurationClassLoader
-
Methods inherited from interface nl.nn.adapterframework.core.ISender
close, sendMessageOrThrow
-
-
-
-
Method Detail
-
configure
public void configure() throws ConfigurationException
Description copied from interface:ISender
configure()
is called once at startup of the framework in the configure method of the owner of this sender. Purpose of this method is to check whether the static configuration of the sender is correct. As much as possible class-instantiating should take place in theconfigure()
oropen()
method, to improve performance.- Specified by:
configure
in interfaceIConfigurable
- Specified by:
configure
in interfaceISender
- Overrides:
configure
in classMailSenderBase
- Throws:
ConfigurationException
-
open
public void open() throws SenderException
Create a session to validate connectivity- Specified by:
open
in interfaceISender
- Overrides:
open
in classSenderBase
- Throws:
SenderException
-
createSession
protected jakarta.mail.Session createSession() throws SenderException
Create the session during runtime- Throws:
SenderException
-
sendEmail
public String sendEmail(MailSenderBase.MailSessionBase mailSession) throws SenderException
- Specified by:
sendEmail
in classMailSenderBase
- Throws:
SenderException
-
createMailSession
protected MailSender.MailSession createMailSession() throws SenderException
- Specified by:
createMailSession
in classMailSenderBase
- Throws:
SenderException
-
setSmtpHost
public void setSmtpHost(String newSmtpHost)
Name of the SMTP-host by which the messages are to be send
-
setSmtpPort
public void setSmtpPort(int newSmtpPort)
Port of the SMTP-host by which the messages are to be send- Default value
- 25
-
getSmtpHost
public String getSmtpHost()
-
getSmtpPort
public int getSmtpPort()
-
-