Java class implementation:
com.orientechnologies.orient.server.plugin.mail.OMailPlugin
Available since: v. 1.2.0.
Allows to send (and in future read) emails.
This plugin is configured as a Server handler. The plugin can be configured in easy way by changing parameters:
Name | Description | Type | Example | Since |
---|---|---|---|---|
enabled | true to turn on, false (default) is turned off | boolean | true | 1.2.0 |
profile.<name>.mail.smtp.host | The SMTP host name or ip-address | string | smtp.gmail.com | 1.2.0 |
profile.<name>.mail.smtp.port | The SMTP port | number | 587 | 1.2.0 |
profile.<name>.mail.smtp.auth | Authenticate in SMTP | boolean | true | 1.2.0 |
profile.<name>.mail.smtp.starttls.enable | Enable the starttls | boolean | true | 1.2.0 |
profile.<name>.mail.smtp.user | The SMTP username | string | yoda@starwars.com | 1.2.0 |
profile.<name>.mail.from | The source's email address | string | yoda@starwars.com | 1.7 |
profile.<name>.mail.smtp.password | The SMTP password | string | UseTh3F0rc3 | 1.2.0 |
profile.<name>.mail.date.format | The date format to use, default is "yyyy-MM-dd HH:mm:ss" | string | yyyy-MM-dd HH:mm:ss | 1.2.0 |
Default configuration in orientdb-server-config.xml. Example:
<!-- MAIL, TO TURN ON SET THE 'ENABLED' PARAMETER TO 'true' -->
<handler
class="com.orientechnologies.orient.server.plugin.mail.OMailPlugin">
<parameters>
<parameter name="enabled" value="true" />
<!-- CREATE MULTIPLE PROFILES WITH profile.<name>... -->
<parameter name="profile.default.mail.smtp.host" value="smtp.gmail.com"/>
<parameter name="profile.default.mail.smtp.port" value="587" />
<parameter name="profile.default.mail.smtp.auth" value="true" />
<parameter name="profile.default.mail.smtp.starttls.enable" value="true" />
<parameter name="profile.default.mail.from" value="test@gmail.com" />
<parameter name="profile.default.mail.smtp.user" value="test@gmail.com" />
<parameter name="profile.default.mail.smtp.password" value="mypassword" />
<parameter name="profile.default.mail.date.format" value="yyyy-MM-dd HH:mm:ss" />
</parameters>
</handler>
The message is managed as a map of properties containing all the fields those are part of the message.
Supported message's properties:
Name | Description | Mandatory | Example | Since |
---|---|---|---|---|
from | source email address | No | to : "first@mail.com", "second@mail.com" | 1.7 |
to | destination addresses separated by commas | Yes | to : "first@mail.com", "second@mail.com" | 1.2.0 |
cc | Carbon copy addresses separated by commas | No | cc: "first@mail.com", "second@mail.com" | 1.2.0 |
bcc | Blind Carbon Copy addresses separated by commas | No | bcc : "first@mail.com", "second@mail.com" | 1.2.0 |
subject | The subject of the message | No | subject : "This Email plugin rocks!" | 1.2.0 |
message | The message's content | Yes | message : "Hi, how are you mate?" | 1.2.0 |
date | The subject of the message. Pass a java.util.Date object or a string formatted following the rules specified in "mail.date.format" configuration parameter or "yyyy-MM-dd HH:mm:ss" is taken | No, if not specified current date is assumed | date : "2012-09-25 13:20:00" | 1.2.0 |
attachments | The files to attach | No | attachments : "tmp/2.eml" | 1.2.0 |
The Email plugin install a new variable in the server-side function's context: "mail". "profile" attribute is the profile name in configuration.
Example to send an email writing a function in JS:
mail.send({
profile : "default",
to: "orientdb@ruletheworld.com",
cc: "yoda@starwars.com",
bcc: "darthvader@starwars.com",
subject: "The EMail plugin works",
message : "Sending email from OrientDB Server is so powerful to build real web applications!"
});
On Nashorn (>= Java8) the mapping of JSON to Map is not implicit. Use this:
mail.send( new java.util.HashMap{
profile : "default",
to: "orientdb@ruletheworld.com",
cc: "yoda@starwars.com",
bcc: "darthvader@starwars.com",
subject: "The EMail plugin works",
message : "Sending email from OrientDB Server is so powerful to build real web applications!"
});
OMailPlugin plugin = OServerMain.server().getPlugin("mail");
Map<String, Object> message = new HashMap<String, Object>();
message.put("profile", "default");
message.put("to", "orientdb@ruletheworld.com");
message.put("cc", "yoda@starts.com,yoda-beach@starts.com");
message.put("bcc", "darthvader@starwars.com");
message.put("subject", "The EMail plugin works");
message.put("message", "Sending email from OrientDB Server is so powerful to build real web applications!");
plugin.send(message);