Skip to content

yure/storemail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

StoreMail

SYNOPSIS

Emails API.

CONFIGURATION

Config files

Setup mailing provider and DB info in config.yml. Example below:

domain: domain.com

gmail:
  accounts:
    Info:
      host: 'imap.gmail.com'
      port: 993
      username: '[email protected]'
      password: 'passss'
      ssl: 1
    Sales:
      domain: prevajalska-agencija.hr 
      host: 'imap.gmail.com'
      port: 993
      username: '[email protected]'
      password: 'passs'
      ssl: 1

plugins:
  DBIC:
    default:
      dsn: dbi:mysql:dbname=StoreMail
      schema_class: StoreMail::Schema
      user: root
      pass: toor
      options:
        mysql_enable_utf8: 1

  

DB deploy

You can easily deploy DB after you have set up config with

bin/deploy.pl
  

Running services

You need to run dancer application (bin/app.pl), to handle API requests Mails sent are added to send queue so you have to mail queue service to actually send them.

Gmail fetch

bin/get_gmail_daemon.pl --start

Options are:

--start Starts daemon
--stop Stops daemon
--redirect Redirects all sent mail to set email. Argument must be before --start!
--logfile Logfile path/name. Argument must be before --start!

Log are in logs dir.

PID file is located in run dir in storemail dir. You can set custom path it in config.

pid_dir: /var/run
 

You have to set 'domain' and 'gmail' setting in config. Default sleep between tries is 10sec. You can set 'get_gmail_sleep' in config.

Initial import

bin/get_gmail.pl --init

Log is in initial_import_log.txt

MailQueue service

bin/mail_queue_daemon.pl --redirect [email protected] --start

Options are:

--start Starts daemon
--stop Stops daemon
--redirect Redirects all sent mail to set email. Argument must be before --start!
--logfile Logfile path/name. Argument must be before --start!

By default it checks for new mail on queue every 3sec (setting in config mail_queue_sleep).

mail_queue_sleep: 3

Provider

Wokring GUI example on /:domain/gui/provider/:comma_separated_emails

JS and HTML code in views/provider.html

Send mail

POST /:domain/message/send

Send email via some GUI. Example use:

$("#replay-form").submit(function(e) {
                var message = {
                        from: this.from.value,
                        to: this.to.value,
                        cc: this.cc.value,
                        bcc: this.bcc.value,
                        subject: this.subject.value,
                        body: this.body.value,
                        body_type: 'html', //(or 'plain by default)
                        tags: 'ad,someOtherTag'
                        attachments: [
                                {
                                        content: "data:text/plain;base64,Y2131....",
                                        name: 'text.txt'
                                },
                }
        
                $.ajax({
                        type : "POST",
                        url : '/' + domain + '/message/send',
                        data : {data: JSON.stringify(message)},
                        dataType : 'json',
                        success: function(data) {
                                update_con();
                        },
                });
                return false; // avoid to execute the actual submit of the form.
        });     
        

Attachments

Are base64 encoded in JSON-

Sample - add one attachment:

HTML <label>Attachments</label> <input id="attachment" name="file" type="file"/>

JS var attachments = []; function readFile(input) { if ( input.files && input.files[0] ) { var filename = input.files[0].name; var FR= new FileReader(); FR.onload = function(e) { attachments.push({name: filename, content: e.target.result}); }; FR.readAsDataURL( input.files[0] ); } }

$("#attachment").change(function(){
    readFile( this );
});
        

Get provider emails

GET /:domain/provider/:comma_separated_emails

Get provider unread emails

GET /:domain/provider/unread/:comma_separated_emails

Get all unread emails

GET /:domain/message/unread

returns JSON.

Sample:

{ "messages" : 
        [ 
                { 
                        "from" : "[email protected]" 
                        "to" : [ "[email protected] ], 
                        "cc" : [], 
                        "bcc" : [], 
                        "subject" : "Welcome", 
                        "body" : "Hello! Have a nice day! Regards", 
                        "attachments" : [], 
                },
                { 
                        "from" : "[email protected]" 
                        "to" : [ "[email protected] ], 
                        "cc" : [], 
                        "bcc" : [], 
                        "subject" : "RE: Welcome", 
                        "body" : "Thanks!", 
                        "attachments" : [], 
                },
        ]
}

Tags

You can set, delete, check and retrieve all tags from message.

Example adding 'read' tag:

GET /:domain/message/:id/tag/check/read

0

GET /:domain/message/:id/tag/add/read

0

GET /:domain/message/:id/tag/check/read

1

GET /:domain/message/:id/tag/check/get_all

{
   "tags" : [
      "read",      
   ]
}