public class EmailSender extends Object
Mainly this class does only one thing. The sending of email messages. But to do it it's necessary to provide set
of configuration parameters that makes the code of RPA process overloaded and complex to understand. Using of
RPAServicesAccessor this class gets all necessary configuration parameters and thus moving out the
definition of them from RPA process code. In conjunction with using of Inject annotation the sending of
email messages becomes easy and clear:
@Inject
private EmailSender emailSender;
public void execute() {
...
emailSender.send(new EmailMessage().subject("Test email").text("This message was sent by robot."));
...
}
EmailMessage| Constructor and Description |
|---|
EmailSender()
Default constructor of this EmailSender.
|
EmailSender(eu.easyrpa.openframework.core.sevices.RPAServicesAccessor rpaServices)
Constructs EmailSender with provided
RPAServicesAccessor. |
| Modifier and Type | Method and Description |
|---|---|
OutboundEmailProtocol |
getProtocol()
Gets protocol that is necessary to use for working with outbound email server.
|
String |
getSecret()
Gets JSON string with secret information necessary to perform authentication to specific mailbox on
the server.
|
String |
getServer()
Gets outbound email server URL.
|
EmailSender |
protocol(OutboundEmailProtocol protocol)
Sets explicitly the value of protocol that is necessary to use for working with outbound email server.
|
EmailSender |
protocol(String protocol)
Sets explicitly the value of protocol that is necessary to use for working with outbound email server.
|
EmailSender |
secret(String secret)
Sets explicitly the value of secret information necessary to perform authentication to specific mailbox on
the server.
|
EmailSender |
secret(String userName,
String password)
Sets explicitly credentials necessary to perform authentication to specific mailbox on the server.
|
void |
send(EmailMessage message)
Sends given email message.
|
EmailSender |
server(String emailServerHostAndPort)
Sets explicitly the value of outbound email server URL.
|
void |
setProtocol(OutboundEmailProtocol protocol)
Sets explicitly the value of protocol that is necessary to use for working with outbound email server.
|
void |
setSecret(String secret)
Sets explicitly the value of secret information necessary to perform authentication to specific mailbox on
the server.
|
void |
setServer(String emailServerHostAndPort)
Sets explicitly the value of outbound email server URL.
|
public EmailSender()
This constructor should be used in case of manual providing of parameters for connection with outbound email server or if its necessary to work with more than one email server at the same time. E.g.:
EmailSender sender1 = new EmailSender().server("smtp1.mail.com").protocol("smtp_over_tsl")
.secret("{ \"user\": \"user1@mail.com\", \"password": \"passphrase\" }");
EmailSender sender2 = new EmailSender().server("smtp2.mail.com").protocol("smtp_over_tsl")
.secret("{ \"user\": \"user2@mail.com\", \"password": \"passphrase\" }");
...
});
@Inject public EmailSender(eu.easyrpa.openframework.core.sevices.RPAServicesAccessor rpaServices)
RPAServicesAccessor.
This constructor is used in case of injecting of this EmailSender using Inject annotation. This is
preferable way of working with this class. E.g.:
@Inject
private EmailSender emailSender;
public void execute() {
...
new EmailMessage(emailSender).subject(SUBJECT).text(BODY).send();
...
}
rpaServices - instance of RPAServicesAccessor that allows to use provided by RPA platform services
like configuration, secret vault etc.EmailMessagepublic String getServer()
If this server URL is not specified explicitly then it will be looked up in configurations parameters of the
RPA platform under the key outbound.email.server.
public void setServer(String emailServerHostAndPort)
This parameter can be changed at any time of working with this class. It will switch to work with a new value before calling of next service method.
emailServerHostAndPort - outbound email server URL with host name and port to set.public EmailSender server(String emailServerHostAndPort)
This parameter can be changed at any time of working with this class. It will switch to work with a new value before calling of next service method.
emailServerHostAndPort - outbound email server URL with host name and port to set.public OutboundEmailProtocol getProtocol()
If this protocol is not specified explicitly then it will be looked up in configurations parameters of the
RPA platform under the key "outbound.email.protocol".
If it's not specified in configurations parameters either then "smtp" protocol will be
used as default.
OutboundEmailProtocol representing necessary to use protocol.public void setProtocol(OutboundEmailProtocol protocol)
This parameter can be changed at any time of working with this class. It will switch to work with a new value before calling of next service method.
protocol - OutboundEmailProtocol that is necessary to use.public EmailSender protocol(OutboundEmailProtocol protocol)
This parameter can be changed at any time of working with this class. It will switch to work with a new value before calling of next service method.
protocol - OutboundEmailProtocol that is necessary to use.public EmailSender protocol(String protocol)
This parameter can be changed at any time of working with this class. It will switch to work with a new value before calling of next service method.
protocol - string with name of protocol that is necessary to use.public String getSecret()
The JSON string format depends on the protocol used by this client. But in most cases it looks like the following:
{ "user": "email@dress", "password": "passphrase" }
If this secret string is not specified explicitly then at it will be looked up in secret vault of the
RPA platform. The secret vault alias that is necessary to lookup is expected to be specified in configuration
parameters under the key "outbound.email.secret".
public void setSecret(String secret)
The secret information should be in JSON format. Specific format depends on the protocol used by this client. But in most cases it should look like the following:
{ "user": "email@dress", "password": "passphrase" }
This parameter can be changed at any time of working with this class. It will switch to work with a new value before calling of next service method.
secret - JSON string with secret information to set.public EmailSender secret(String secret)
The secret information should be in JSON format. Specific format depends on the protocol used by this client. But in most cases it should look like the following:
{ "user": "email@dress", "password": "passphrase" }
This parameter can be changed at any time of working with this class. It will switch to work with a new value before calling of next service method.
secret - JSON string with secret information to set.public EmailSender secret(String userName, String password)
These parameters can be changed at any time of working with this class. It will switch to work with new values before calling of next service method.
userName - email address of the necessary mailbox.password - pass phrase to access the necessary mailbox.public void send(EmailMessage message)
message - the email message to send.EmailMessagingException - in case of some errors.Copyright © 2023. All rights reserved.