Mail Plugin

Java class implementation:

  1. com.orientechnologies.orient.server.plugin.mail.OMailPlugin

Available since: v. 1.2.0.

Introduction

Allows to send (and in future read) emails.

Configuration

This plugin is configured as a Server handler. The plugin can be configured in easy way by changing parameters:

NameDescriptionTypeExampleSince
enabledtrue to turn on, false (default) is turned offbooleantrue1.2.0
profile.<name>.mail.smtp.hostThe SMTP host name or ip-addressstringsmtp.gmail.com1.2.0
profile.<name>.mail.smtp.portThe SMTP portnumber5871.2.0
profile.<name>.mail.smtp.authAuthenticate in SMTPbooleantrue1.2.0
profile.<name>.mail.smtp.starttls.enableEnable the starttlsbooleantrue1.2.0
profile.<name>.mail.smtp.userThe SMTP usernamestringyoda@starwars.com1.2.0
profile.<name>.mail.fromThe source’s email addressstringyoda@starwars.com1.7
profile.<name>.mail.smtp.passwordThe SMTP passwordstringUseTh3F0rc31.2.0
profile.<name>.mail.date.formatThe date format to use, default is “yyyy-MM-dd HH:mm:ss”stringyyyy-MM-dd HH:mm:ss1.2.0

Default configuration in orientdb-server-config.xml. Example:

  1. <!-- MAIL, TO TURN ON SET THE 'ENABLED' PARAMETER TO 'true' -->
  2. <handler
  3. class="com.orientechnologies.orient.server.plugin.mail.OMailPlugin">
  4. <parameters>
  5. <parameter name="enabled" value="true" />
  6. <!-- CREATE MULTIPLE PROFILES WITH profile.<name>... -->
  7. <parameter name="profile.default.mail.smtp.host" value="smtp.gmail.com"/>
  8. <parameter name="profile.default.mail.smtp.port" value="587" />
  9. <parameter name="profile.default.mail.smtp.auth" value="true" />
  10. <parameter name="profile.default.mail.smtp.starttls.enable" value="true" />
  11. <parameter name="profile.default.mail.from" value="test@gmail.com" />
  12. <parameter name="profile.default.mail.smtp.user" value="test@gmail.com" />
  13. <parameter name="profile.default.mail.smtp.password" value="mypassword" />
  14. <parameter name="profile.default.mail.date.format" value="yyyy-MM-dd HH:mm:ss" />
  15. </parameters>
  16. </handler>

Usage

The message is managed as a map of properties containing all the fields those are part of the message.

Supported message properties:

NameDescriptionMandatoryExampleSince
fromsource email addressNoto : “first@mail.com”, “second@mail.com”1.7
todestination addresses separated by commasYesto : “first@mail.com”, “second@mail.com”1.2.0
ccCarbon copy addresses separated by commasNocc: “first@mail.com”, “second@mail.com”1.2.0
bccBlind Carbon Copy addresses separated by commasNobcc : “first@mail.com”, “second@mail.com”1.2.0
subjectThe subject of the messageNosubject : “This Email plugin rocks!”1.2.0
messageThe message’s contentYesmessage : “Hi, how are you mate?”1.2.0
dateThe 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 takenNo, if not specified current date is assumeddate : “2012-09-25 13:20:00”1.2.0
attachmentsThe files to attachNo1.2.0

From Server-Side Functions

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:

  1. mail.send({
  2. profile : "default",
  3. to: "orientdb@ruletheworld.com",
  4. cc: "yoda@starwars.com",
  5. bcc: "darthvader@starwars.com",
  6. subject: "The EMail plugin works",
  7. message : "Sending email from OrientDB Server is so powerful to build real web applications!"
  8. });

On Nashorn (>= Java8) the mapping of JSON to Map is not implicit. Use this:

  1. mail.send( new java.util.HashMap{
  2. profile : "default",
  3. to: "orientdb@ruletheworld.com",
  4. cc: "yoda@starwars.com",
  5. bcc: "darthvader@starwars.com",
  6. subject: "The EMail plugin works",
  7. message : "Sending email from OrientDB Server is so powerful to build real web applications!"
  8. });

From Java

  1. OMailPlugin plugin = OServerMain.server().getPlugin("mail");
  2. Map<String, Object> message = new HashMap<String, Object>();
  3. message.put("profile", "default");
  4. message.put("to", "orientdb@ruletheworld.com");
  5. message.put("cc", "yoda@starts.com,yoda-beach@starts.com");
  6. message.put("bcc", "darthvader@starwars.com");
  7. message.put("subject", "The EMail plugin works");
  8. message.put("message", "Sending email from OrientDB Server is so powerful to build real web applications!");
  9. plugin.send(message);