It is currently Sun Feb 12, 2012 9:59 am

All times are UTC + 2 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: sending / receiving email using mailgate
PostPosted: Fri Sep 11, 2009 11:53 am 
Offline

Joined: Fri Mar 13, 2009 12:41 pm
Posts: 43
Location: London, UK
In case this is useful to someone trying to get mailgate up an running, have a look.

I put this little procedure together so I can reference it later. Based on what's in the book and hda's threads. Running on ubuntu 8.04.

Getting OpenERP to send / receive email using mailgate
1)Start OpenERP server with the smtp flag using an open relay SMTP server. This setting is what allows OpenERP to send out emails.
python openerp-server.py --smtp 172.30.0.10

The above example uses spamtitan on the LAN. My experimentation with SBS was a bit difficult here since you don’t really want to allow open relay. Another possible solution if something like SpamTitan or the ISP’s SMTP server is not available is to install sendmail or a similar program on the OpenERP box and have it relay.

2)Fetchmail – Fetchmail is used to get a copy of emails from the email server and then run an Openerp python script to import/create cases in the system automatically depending on the settings below.
a.Install Fetchmail
i. sudo apt-get install fetchmail

b.create file called fetchmailrc (this should be in the same directory you run fetchmail from)
i. gedit fetchmailrc
ii.File contents:

# fetchmailrc

poll 172.30.0.20 proto imap:

username helpdeskqueue password abc123 mda “/home/colin/openerp-dev/3/addons/crm/scripts/openerp-mailgate/openerp-mailgate.py –u 1 –p admin –s 3 –e helpdeskqueue@company.com –d admin”

iii.File contents explained:
1.The poll command is pointed to your mail server. The proto (short for protocol) can be IMAP or POP depending on what is available.
2.* note – the commands/entries above are all separated by a space
3.username – the email account username
4.password – the email user password
5.mda – flag to pass all the stuff in double quotes to fetchmail and allows the python scripts to run.
6./home/colin/openerp-dev/.... – this is the path to the openerp-mailgate.py file
7.–u 1 -this is the id number of the user in OpenERP that will access the database. Log on to openerp and check this ID field. In this example id 1 is the admin user.
8.–p -this is the password of the openerp user from above
9.–s 3 - s stands for Section. The sections are CRM --> Configuration--> Cases --> Sections. Like the user ID each section has an ID number and this needs to be put here.
10.–e -the email address of the email account
11.–d -the name of the database stored in Postgres

c.Running Fetchmail - keep in mind that this command runs fetchmail once, it's not continuously grabbing emails, but it's enough for testing and to get started.
i.Command syntax –
fetchmail –v –k –f fetchmailrc

ii.Command syntax explained
1.–v this is the verbose flag. This is Optional.
2.–k this makes fetchmail leave a copy of the email fetched on the server. For IMAP this needs to be set but possibly not for POP.
3.–f this tells fetchmail we will be passing a file with additional commands, in this case the file is called fetchmailrc. Actually any file name seems to work.

Sorry about the formatting, this had been cut and pasted from a word doc.

That's it. Now you can send emails to the mailbox you set up above and after running fetchmail OpenERP will automatically create the case in the system :)
The 'Send Partner & Historize' button will also work providing your smtp server is happy about relaying emails from OpenERP.


Top
 Profile  
 
 Post subject: Rolling log files
PostPosted: Sat Nov 21, 2009 1:12 am 
Offline

Joined: Fri Apr 24, 2009 8:36 pm
Posts: 54
I wish I'd seen this post before I waded through the set up on my own.

Anyway, here's another step that I just figured out: rolling over the mailgate.log. It seems like a good idea, because the mailgate dumps a complete copy of every e-mail it sends.

Here's an article on configuring logrotate to roll the logs. I created a file called /etc/logrotate.d/openerp with the following contents:

Quote:
/path/to/openerp/addons/crm/scripts/openerp-mailgate/mailgate.log {
weekly
rotate 10
copytruncate
delaycompress
compress
notifempty
missingok
}


If this works, I'll probably add entries for the other openerp log files.

I'm running on Ubuntu Intrepid. I've just set this stuff up, so I'll have to wait for a week to make sure things work.

I found this blog post helpful for installing exim4 to forward e-mail from the openerp server to the ISP's SMTP server.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 19, 2010 2:09 am 
Offline

Joined: Fri Apr 24, 2009 8:36 pm
Posts: 54
Ignore what I said above about rolling over the logs. I think I must have added the logging as a debugging tool. (Oops.)

One other thing that isn't covered by the posts here is how to make fetchmail run automatically when the server is rebooted. I found this post very helpful. Pay particular attention to the call to update-rc.d, I missed it the first time.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 16, 2010 11:29 pm 
Offline

Joined: Sat May 19, 2007 5:43 pm
Posts: 62
Location: Argentina
I have an idea...why not just rewrite the mailgate class to be more human like...i mean, just configuring a server, a port a username and a password...like any other sane ERP system...

PD: Many years waiting this...sorry


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 20, 2010 6:13 pm 
Offline

Joined: Fri Mar 13, 2009 5:16 pm
Posts: 28
Location: United kingdom
razor7 wrote:
I have an idea...why not just rewrite the mailgate class to be more human like...i mean, just configuring a server, a port a username and a password...like any other sane ERP system...

PD: Many years waiting this...sorry



Could not agree more!! What a joke!!


Top
 Profile  
 
 Post subject: Error trying openerp-mailgate.py
PostPosted: Wed Mar 03, 2010 8:24 pm 
Offline

Joined: Wed Mar 03, 2010 7:56 pm
Posts: 2
I'm getting this error when I try to use openerp-mailgate.py

Code:
fetchmail: POP3> RETR 1
fetchmail: POP3< +OK message follows
reading message soporte@request.com.ar@gmail-pop.l.google.com:1 of 1 (2414 octets)
#***********<Fault AccessDenied: 'Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/netsvc.py", line 244, in dispatch
    result = LocalService(service_name)(method, *params)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/netsvc.py", line 73, in __call__
    return getattr(self, method)(*params)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/service/web_services.py", line 574, in execute
    security.check(db, uid, passwd)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/addons/use_control/services.py", line 60, in check_one
    return chk_fnct(db, uid, passwd)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/service/security.py", line 57, in check
    raise Exception(\'AccessDenied\')
Exception: AccessDenied
>
<Fault>
cannot marshal None unless allow_none is enabled
cannot marshal None unless allow_none is enabled
not flushed
fetchmail: POP3> QUIT


I've modified the script so the default values are the ones I need for testing purposes:

Code:
if __name__ == '__main__':
    import sys, optparse
    parser = optparse.OptionParser(
        usage='usage: %prog [options]',
        version='%prog v1.0')

    group = optparse.OptionGroup(parser, "Note",
        "This program parse a mail from standard input and communicate "
        "with the Open ERP server for case management in the CRM module.")
    parser.add_option_group(group)

    parser.add_option("-u", "--user", dest="userid", help="ID of the user in Open ERP", default=2, type='int')
    parser.add_option("-p", "--password", dest="password", help="Password of the user in Open ERP", default='admin')
    parser.add_option("-e", "--email", dest="email", help="Email address used in the From field of outgoing messages", default="soporte@request.com.ar")
    parser.add_option("-s", "--section", dest="section", help="ID or code of the case section", default="2")
    parser.add_option("-m", "--default", dest="default", help="Default eMail in case of any trouble.", default="soporte@request.com.ar")
    parser.add_option("-d", "--dbname", dest="dbname", help="Database name (default: terp)", default='REQUEST')

    (options, args) = parser.parse_args()
    parser = email_parser(options.userid, options.password, options.section, options.email, options.default, dbname=options.dbname)

    msg_txt = email.message_from_file(sys.stdin)

    try :
        parser.parse(msg_txt)
    except Exception,e:
        if getattr(e,'faultCode','') and 'Connection unexpectedly closed' in e.faultCode:
            print e


The fetchamilrc:
Code:
# fetchmailrc

poll pop.gmail.com with proto POP3:

username 'soporte@request.com.ar' password <password> mda "/home/leandrochao/openerp-server-5.0.6/bin/addons/crm/scripts/openerp-mailgate/openerp-mailgate.py" options keep ssl



I just don't know what I'm missing here.
Any help would be appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2010 11:55 pm 
Offline

Joined: Fri Apr 24, 2009 8:36 pm
Posts: 54
It looks like that error means that the OpenERP user id and password combination don't match any records in the database. Are you sure that you want user id 2? Usually the admin user is id 1. If you really do mean user id 2, then are you sure that it uses the password 'admin'?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2010 12:28 am 
Offline

Joined: Sat Jun 27, 2009 4:08 am
Posts: 82
Location: Buenos Aires - Argentina
this is a security issue...
userid=2? are you sure? usually admin = 1...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2010 2:15 am 
Offline

Joined: Wed Mar 03, 2010 7:56 pm
Posts: 2
You are right. I followed wrong the guide to get the user id.
Thanks for helping a newbie


Top
 Profile  
 
 Post subject: Re: sending / receiving email using mailgate
PostPosted: Tue Oct 26, 2010 8:50 pm 
Offline

Joined: Fri Apr 30, 2010 10:35 am
Posts: 90
hello,

what about antivirus/antispam?
do you have to take care of those, before fetchmail hands the mails over to the mailgate?

thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP