I finish the mails integrations clients and services base clases to be used
in Zato, they are available at https://github.com/aek/zato-labs, a fork of
https://github.com/zatosource/zato-labs, also I made a pull request with
the new code to the original repo.
There are now a way to interacts with SMTP, IMAP and POP3 servers.
SMTP is for send mails,
IMAP and POP3 for fetch mails and they return a set of dicts with mails
information ready to be processed at the service.
To get this works the following keys need to be set on Redis, just the set
that you need for the service you want to use, not all of them
[smtp]
set zato:mail:conn-info:smtp_host:app-mail smtp.gmail.com
set zato:mail:conn-info:smtp_port:app-mail 465
set zato:mail:conn-info:smtp_user:app-mail example@gmail.com
set zato:mail:conn-info:smtp_pass:app-mail mypassword
set zato:mail:conn-info:smtp_encryption:app-mail ssl
set zato:mail:conn-info:smtp_debug:app-mail True
[imap]
set zato:mail:conn-info:imap_host:app-mail imap.gmail.com
set zato:mail:conn-info:imap_port:app-mail 993
set zato:mail:conn-info:imap_user:app-mail example@gmail.com
set zato:mail:conn-info:imap_pass:app-mail mypassword
set zato:mail:conn-info:imap_ssl:app-mail True
[pop3]
set zato:mail:conn-info:pop3_host:app-mail pop.gmail.com
set zato:mail:conn-info:pop3_port:app-mail 995
set zato:mail:conn-info:pop3_user:app-mail example@gmail.com
set zato:mail:conn-info:pop3_pass:app-mail mypassword
set zato:mail:conn-info:pop3_ssl:app-mail True
all the keys have the format:
zato:mail:conn-info:param:app-mail
app-mail is:
the name to use in your services to retrieve the connection information to
the service client to connect. need to be used as part of every key to this
connection information. You can use any name for this
param can be:
imap_host, pop3_host and smtp_host are the hostname or ip address of the
email service to connect
imap_port, pop3_port and smtp_port are the port of the email service to
connect
imap_user, pop3_user and smtp_user are the username used to connect to the
email service
imap_pass, pop3_pass and smtp_pass are the password used to connect to the
email service
imap_ssl and pop3_ssl are the definition of connection security to the
service
smtp_encryption is the kind of security encryption used to connect to the
smtp based service
smtp_debug is whenever or not the service log smtp service output
The following are demos of HowTo use it in Zato Services
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function,
unicode_literals
from zato.server.service import Service
from zato.mail import IMAPService
class IMAPServiceTest(IMAPService):
def handle(self):
conn = self.imap.get('app-mail')
msgs = conn.fetch_mail()
self.logger.info(str(msgs))
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function,
unicode_literals
from zato.server.service import Service
from zato.mail import POP3Service
class POP3ServiceTest(POP3Service):
def handle(self):
conn = self.pop3.get('app-mail')
msgs = conn.fetch_mail()
self.logger.info(str(msgs))
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function,
unicode_literals
from zato.server.service import Service
from zato.mail import SMTPService
class SMTPServiceTest(SMTPService):
def handle(self):
conn = self.smtp.get('app-mail')
msg = conn.build_email("example@gmail.com", ["example@gmail.com",], "email
from zato", "hello worl from zato")
conn.send_email(msg)
Hope it helpful
On Sat, Feb 15, 2014 at 5:56 AM, Dariusz Suchojad dsuch@zato.io wrote:
On 02/14/2014 11:55 PM, Axel Mendoza Pupo wrote:
What are the requisites for the IMAP task, they are not clear in the
issue,
I ask because I can provide it based on OpenERP fetchmail module, and it
can be another thing done for get the next release sooner than expected.
If
this is ok with you can you explain what need to be done for get the IMAP
task finished?.
Thanks for asking, Axel.
The IMAP component needs to take the following parameters
- host (TLS should be supported too)
- port
- username
- password
- list of folder names
- list of file patterns
- interval
- callback service
- flag download/notify
and it should periodically connect to IMAP servers checking the contents
of folders for files matching the patterns - if any new are added since
the last time it runs the callback service with either the contents of
new files (flag download) or information that a new file is available
(flag notify).
Now, if you could add the part that connects to IMAP basing on
parameters in Redis - the way it’s done in zato-labs for OpenERP and
SMTP, I would add the remaining pieces before 1.2 - I just wouldn’t want
to burden you with implementing it all. Any help would be greatly
appreciated 
What do you think?