StoreMail
Emails API.
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
You can easily deploy DB after you have set up config with
bin/deploy.pl
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.
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.
bin/get_gmail.pl --init
Log is in initial_import_log.txt
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
Wokring GUI example on /:domain/gui/provider/:comma_separated_emails
JS and HTML code in views/provider.html
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.
});
Are base64 encoded in JSON-
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 /:domain/provider/:comma_separated_emails
GET /:domain/provider/unread/:comma_separated_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" : [],
},
]
}
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",
]
}