E-mail post-processing and automation.

NikaMail allows to handle incoming emails by writing post-processing hooks in Ruby.

You can do practically everything with emails, for example: Redirect emails, Parse content, Write to database, Hadle attached files, and more..

Registering hooks

A mailbox hook is simply a Ruby method which receives a parsed .eml file when it is delivered to mailbox.

In order to register a hook edit app/hooks.rb. A hook is related to mailbox name, you can add more than one hook and they will be executed in order.

def self.registry
    return @registry if @registry
      mario: [ method(:print_mario_emails)] # <- here is the hooks for 'mario'
    return @registry
def self.print_mario_emails(eml)
    puts "Post-processing is here"
    puts "
      From: #{eml.From}
      Subject: #{eml.Subject}
      SubjectID: #{eml.SubjectID}
      Date: #{eml.Date}
      Files: #{ {|f| f.filename}}
      Body: #{eml.Body.Content}

Parsing Raw Emails

NikaMail provides a parser for raw *.eml files. The class Eml is available globally and you can use it in your mailbox extensions. By default all hooks receive a pased email as first argument.

class Eml

Method: new(String file, Bool raw)

Creates an email instance from file path or raw data. By default flag raw is false.

Method: copy(String mailbox_1, String mailbox_2)

Copy email to another mailbox.

Method: setTo(String address)

Set email receiver

Method: setFrom(String address)

Set email sender

Method: setSubject(String subject)

Set email subject

@Attribute: From

Canonical email address: “John Doe <>“

@Attribute: AddressFrom

Email address: “”

@Attribute: To

Canonical email address: “Jane Doe <>“

@Attribute: AddressTo

Email address: “”

@Attribute: Subject

Email subject

@Attribute: SubjectID

An Id retrieved from inside square parentheses. If subject is Message [123456122] the id would be 123456122

@Attribute: Body

Email body

@Attribute: Files

Email attachments (Array[])

@Attribute: raw

Raw email

Usage Example:

email =
sender = email.From
attachments = email.Files
pdf = attachments[0]
puts pdf.filename

email.setSubject('PDF document 123')
email.copy([box1, box2])


If you need a third party library use following command to install ruby gems.

bin/jruby -S gem install awesomegem