Skip to main content


MongoDB is a cross-platform document-oriented database. This plugin provide a bridge for MongoDB databases.


In this example, we will setup the plugin to be used in the SMTP SMTP Receiver service. First, create a connection to the MongoDB database.

// /etc/vsmtp/smtp-receiver/services/db.rhai
// Import the plugin stored in the `plugins` directory.
import "plugins/libvsmtp_plugin_mongodb" as mongodb;

export const bridge = mongodb::connect("mongodb://admin:pass@localhost:27017");

Then query or mutate the database in your rules.

import "services/db" as db;

fn on_connect(ctx) {[
action "find a document in my collection" || {
let database = db::bridge.database("my_database");
let collection = database.collection("greylist");
"email": "",
"name": "John"
"email": ""
"name": "Jenny"
let user = collection.find_one(#{
"name": "John"
log("info", `the email is: ${}`);