(Migrated) New Email Service Component for Zato

(This message has been automatically imported from the retired mailing list)

I just finish a component for sending mails in Zato Services in the Zato
way, like Zato OpenERP integration it require some Redis keys to be set,
it’s based on OpenERP smtplib integration but adapted to Zato.
The way to use it is better to be showed as an example service

# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function,
unicode_literals

from zato.server.service import Service
from zato.mail import MailService


class MailServiceTest(MailService):
def handle(self):
 conn = self.mail.get('app-mail')
#parameters are the followings, for better explanation look at the source,
it has comments
 #build_email(email_from, email_to, subject, body, email_cc=None,
email_bcc=None, reply_to=False, attachments=None, message_id=None,
references=None, object_id=False, subtype='plain', headers=None,
body_alternative=None, subtype_alternative='plain')
 msg = conn.build_email("aekroft@gmail.com", ["aekroft@gmail.com",], "email
from zato service", "hello world from zato")
 conn.send_email(msg)

the following keys need to be added to Redis in order to this works, this
are just example keys

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 email@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

Where the app-mail in keys refers to the smtp connection that you want to
fetch to be used latter in a Zato Service. The values for smtp_encryption
can be any of (‘none’, ‘starttls’, ‘ssl’)

This module is a python dependency that you need to install. The way to
install this in Zato is like all the extra dependencies that you need to
use in your services, just drop it in zato_extra_paths folder of your Zato
instalation or add the paths to the zato or py files in the bin folder of
your Zato installation

Dariusz maybe this can be added to the core or labs
I hope this will be helpful, Enjoy it

On 02/14/2014 04:18 AM, Axel Mendoza Pupo wrote:

I just finish a component for sending mails in Zato Services in the Zato
way, like Zato OpenERP integration it require some Redis keys to be set,
it’s based on OpenERP smtplib integration but adapted to Zato.

[…]

This looks very nice, Axel!

I’ll be definitely adding it to zato-labs soon with the intent of making
part of the 1.2 release after a GUI + a set of admin services are added.

There is already a task to add IMAP …

… on which I will be working in some 5-8 weeks and having SMTP is a
very nice addition :slight_smile:

Thanks again!

On 02/14/2014 04:18 AM, Axel Mendoza Pupo wrote:

I just finish a component for sending mails in Zato Services in the Zato
way, like Zato OpenERP integration it require some Redis keys to be set,
it’s based on OpenERP smtplib integration but adapted to Zato.

[…]

This looks very nice, Axel!

I’ll be definitely adding it to zato-labs soon with the intent of making
part of the 1.2 release after a GUI + a set of admin services are added.

There is already a task to add IMAP …

… on which I will be working in some 5-8 weeks and having SMTP is a
very nice addition :slight_smile:

Thanks again!

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?. I develop the zato-mail because I needed in my work but
only took me a few hours because I have examples source code for what I
need to do in OpenERP, maybe we can reuse the IMAP integration in OpenERP
to build another component for Zato if the requirements are similars.

On Fri, Feb 14, 2014 at 5:01 AM, Dariusz Suchojad dsuch@zato.io wrote:

On 02/14/2014 04:18 AM, Axel Mendoza Pupo wrote:

I just finish a component for sending mails in Zato Services in the Zato
way, like Zato OpenERP integration it require some Redis keys to be set,
it’s based on OpenERP smtplib integration but adapted to Zato.

[…]

This looks very nice, Axel!

I’ll be definitely adding it to zato-labs soon with the intent of making
part of the 1.2 release after a GUI + a set of admin services are added.

There is already a task to add IMAP …

https://github.com/zatosource/zato/issues/98

… on which I will be working in some 5-8 weeks and having SMTP is a
very nice addition :slight_smile:

Thanks again!


Dariusz Suchojad

https://zato.io
ESB, SOA and cloud integrations in Python

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 :slight_smile:

What do you think?