OrientDB Manual 1.7.8

Mail Plugin

Java class implementation:

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:

<!-- 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>

Usage

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

Supported message's 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 attachNoattachments : "tmp/2.eml"1.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:

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!"
  });

From Java

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);