JBStrap mail API
MailAPI
The JBStrap framework supports sending e-mails using JavaMail. You can send plain text or HTML-based emails with the framework. You can also send any number of attachments. Emails can also be forwarded via an open or encrypted email server. To implement this, the framework provides the Email class and the Email API .
The Email class represents an email in the framework. The parameters of the message can be specified in the class, but they are optional. If you specify one or more parameters, the specified parameters override the default ones. If no parameters are specified, the default parameters are used when sending the message. You must specify parameters for each message if you want to send the message to another server instead of the default server.
You do not need to instantiate the Email class but get it from the Email API. Also, the addressee, subject, and text body fields must be entered into the Email instance.
Default email settings must be specified using the *.properties file located in the project resource folder. In the same file, the below keys (only those you want to set) can be specified. Parameters do not have default values, meaning that if a parameter is not specified, it won't be set either.
Key |
Type |
Description |
---|---|---|
mail.smtp.host |
String |
The SMTP server to connect to. |
mail.smtp.port |
int |
The SMTP server port to connect to. Default: 25 |
mail.smtp.socketFactory.port |
int |
Specifies the port to connect to when using the specified socket factory. If not set, the default port will be used. |
mail.smtp.socketFacotry.class |
String |
If set, specifies the name of a class that implements the javax.net .SocketFactory interface. This class will be used to create SMTP sockets. |
mail.smtp.starttls.enable |
boolean |
If true, enables the use of the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands. Defaults to false. |
mail.transport.protocol |
String |
Specifies the default message transport protocol. |
mail.smtp.ssl.enable |
boolean |
If set to true, use SSL to connect and use the SSL port by default. Defaults to false for the "smtp" protocol and true for the "smtps" protocol. |
mail.smtp.ssl.trust |
String |
If set, and a socket factory hasn't been specified, enables use of a MailSSLSocketFactory. If set to "*", all hosts are trusted. If set to a whitespace separated list of hosts, those hosts are trusted. Otherwise, trust depends on the certificate the server presents. |
mail.smtp.auth |
boolean |
If true, attempt to authenticate the user using the AUTH command. Defaults to false. |
mail.smtp.username |
String |
User name for SMTP. |
mail.smtp.password |
String |
Password for SMTP. |
mail.debug.enabled |
boolean |
Enable or disable the debugging. |
Once all parameters are set, you can send emails right away.