Odoo Help


email - how to filter or prevent spam coming into OpenERP?

Gary Miller
on 5/27/13, 11:18 PM 3,199 views

What is the best approach to filtering out spam emails? If a user account has existed for a while, there will be quite a lot of spam flowing into OpenERP. It is a waste to have all the junk mail stored forever in the database. At least I have not found an easy approach to deleting junk mail.

Even more targeted email filtering relates to not allowing in all the Facebook, LinkedIn, Google+ or Twitter messages. Similarly, I would want to filter all subscription/list emails.

GroupMiller, Gary Miller
on 5/31/13, 5:33 PM

This is my concern as well. With a Trac instance where incoming emails generate support tickets, we have to cleanup spam often, otherwise database would suffer. While cleaning up the INBOX, before email reaches the system, is surely a good idea, some kind of filtering later cannot hurt. Note similar question here: http://help.openerp.com/question/18921/how-to-apply-filter-for-emails-in-generating-leads-from-incoming-mail/

on 6/28/13, 9:05 AM

Most of the spam I get is already marked as such by the email firewall. I.e. The subject starts with the string [SPAM-Firewall]_. Is there an easy way to at least prevent issue creation if email.subject.startswith("Whatever"):?

on 7/8/13, 7:56 AM
On 7/23/13, 7:21 AM

You can patch the file addons/fetchmail/fetchmail.py a little bit. In my case, our e-mail firewall already changes the subject of e-mails, if it is probably spam. I just did this:

@@ -198,6 +198,13 @@
                     result, data = imap_server.search(None, '(UNSEEN)')
                     for num in data[0].split():
                         result, data = imap_server.fetch(num, '(RFC822)')
+                        try:
+                            subject = filter(lambda l: l.startswith("Subject: "), data[0][1].split("\n\n")[0].split("\n"))[0].split(" ", 1)[1]
+                            _logger.info("subject: %s", subject)
+                            if subject.startswith("[SPAM-Firewall]_"):
+                                continue
+                        except Exception, e:
+                            _logger.info("exception with subject %s", str(e))
                         res_id = mail_thread.message_process(cr, uid, server.object_id.model, 

If you don't use a firewall, you could easily use the same mechanism to blacklist subjects, senders etc.

michel Guénard
On 5/28/13, 6:47 AM

I have used a service from mailstrom.com to clean the email box from spam and other non-desired emails.

This kind of approach seems to imply that I need to make sure that a filter service runs prior to each time OpenERP checks the email account. - Gary

GroupMiller, Gary Miller
on 5/31/13, 4:53 PM

Services like the one mentionned helps a user to clean his/her mailbox on a continuing basis - as long as the service is active; this is a way to unsubscribe from spam lists. but evidently it does not work as a filter on the fly!

AD LIBITOM, michel Guénard
on 5/31/13, 9:23 PM
Mariusz Mizgier
On 7/26/13, 4:58 AM

Martin - there is a question if you don't mind answering (I would be very glad to get an answer). I'm interested in importing all mail messages from my account, which has been sent directly to me (for example, if my company is @company.com, then I want to have all mails, which have been addressed to me (like mariusz@company.com, where mariusz is my alias), fetched to OpenERP. Here is the code I've modified:

            result, data = imap_server.search(None, '(ALL)')
            for num in data[0].split():
                result, data = imap_server.fetch(num, '(RFC822)')
                    to = filter(lambda l: l.startswith("To: "), data[0][1].split("\n\n")[0].split("\n"))[0].split(" ", 1)[1]
                    _logger.info("to: %s", to)
                    if not to.endswith("@company.com"):
                except Exception, e:
                    _logger.info("exception with address %s", str(e))
                res_id = mail_thread.message_process(cr, uid, server.object_id.model, 

The problem here is that headers are being processed well, but in the end OpenERP fetch 0 mails - what is the problem here? I wasn't able to trace bug here, whole fetchmail processes as follows, but gives 0 exceptions (and it should). It returns a lot of results like INFO test openrp.addons.fetchmail.fetchmail: to: <mariusz@company.com>, but also mails which are not in the domain @company.com. Any help would be appreciated.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 5/27/13, 11:18 PM
Seen: 3199 times
Last updated: 9/15/15, 7:45 AM