groupeurd_newsletter v0.3: robust unsubscribe

Robust and fully flexible html_version and unsubscribe url.
This commit is contained in:
Olivier Sarrat 2017-05-03 19:16:10 +02:00
parent 8f57010cbb
commit 9f8e3f5893
7 changed files with 87 additions and 9 deletions

Binary file not shown.

View File

@ -15,12 +15,13 @@
- Ajouter un champ "unsubscribed_by_odoo_user" qui sera manipulé pour les désincriptions par interface - Ajouter un champ "unsubscribed_by_odoo_user" qui sera manipulé pour les désincriptions par interface
- Afficher champ create_uid pour savoir provenance des contacts - Afficher champ create_uid pour savoir provenance des contacts
- Ne garder que les modèles de courriel de newsletter dans Publipostages/Modèles de courriel - Ne garder que les modèles de courriel de newsletter dans Publipostages/Modèles de courriel
- Retrait insertion automatique lien désinscription
- Message de confirmation de désincription plus verbeux
- Modèles de newsletter spécifiques - Modèles de newsletter spécifiques
- Lien vers version HTML (format proposé: __HTML_VERSION_URL__)
- Placement libre du lien de désinscription (format proposé: __UNSUBSCRIBE_URL__)
En projet: En projet:
- Ecraser les propriétés d'un publipostage par les propriétés standard d'un modèle de courriel au moment de la sélection de ce dernier. - Ecraser les propriétés d'un publipostage par les propriétés standard d'un modèle de courriel au moment de la sélection de ce dernier.
- Message de confirmation de désincription plus verbeux.
""", """,
'author': "Groupe URD", 'author': "Groupe URD",
@ -30,7 +31,7 @@
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml # Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# for the full list # for the full list
'category': 'Marketing', 'category': 'Marketing',
'version': '0.2', 'version': '0.3',
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
'depends': ['base','mass_mailing','marketing','website_mail'], 'depends': ['base','mass_mailing','marketing','website_mail'],

Binary file not shown.

View File

@ -1,8 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import urlparse
import werkzeug.urls
from openerp import models, fields, api from openerp import models, fields, api
from openerp.osv import osv from openerp.osv import osv
from openerp import tools
from openerp.tools.translate import _ from openerp.tools.translate import _
# Overrides mass mailing Contact for this module purpose # Overrides mass mailing Contact for this module purpose
@ -37,8 +41,81 @@ class MailMail(osv.Model):
_inherit = ['mail.mail'] _inherit = ['mail.mail']
def _get_unsubscribe_url(self, cr, uid, mail, email_to, msg=None, context=None): def _get_unsubscribe_url(self, cr, uid, mail, email_to, msg=None, context=None):
return "" base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
url = urlparse.urljoin(
base_url, 'mail/mailing/%(mailing_id)s/unsubscribe?%(params)s' % {
'mailing_id': mail.mailing_id.id,
'params': werkzeug.url_encode({'db': cr.dbname, 'res_id': mail.res_id, 'email': email_to})
}
)
return '%s' % url
def _get_html_version_url(self, cr, uid, mail, email_to, context=None):
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
url = urlparse.urljoin(base_url, 'newsletter/html_version_%s' % mail.mailing_id.id)
return '%s' % url
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None):
email_to = self.send_get_mail_to(cr, uid, mail, partner=partner, context=context)
body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context)
if mail.mailing_id and body and email_to:
emails = tools.email_split(email_to[0])
has_email_to = emails and emails[0] or False
unsubscribe_url = self._get_unsubscribe_url(cr, uid, mail, has_email_to, context=context)
if unsubscribe_url:
body = body.replace('__UNSUBSCRIBE_URL__', unsubscribe_url)
html_version_url = self._get_html_version_url(cr, uid, mail, has_email_to, context=context)
body = body.replace('__HTML_VERSION_URL__', html_version_url)
body_alternative = tools.html2plaintext(body)
res = {
'body': body,
'body_alternative': body_alternative,
'subject': self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context),
'email_to': email_to,
}
return res
class TestMassMailing(osv.TransientModel):
_name = 'mail.mass_mailing.test'
_description = 'Sample Mail Wizard'
email_to = fields.Char('Recipients', required=True,help='Comma-separated list of email addresses.',default=lambda self: self.pool['mail.message']._get_default_from(self.env.cr, self.env.user.id, context=self.env.context))
mass_mailing_id = fields.Many2one('mail.mass_mailing', 'Mailing', required=True, ondelete='cascade')
def send_mail_test(self, cr, uid, ids, context=None):
Mail = self.pool['mail.mail']
for wizard in self.browse(cr, uid, ids, context=context):
mailing = wizard.mass_mailing_id
test_emails = tools.email_split(wizard.email_to)
mail_ids = []
for test_mail in test_emails:
mail_values = {
'email_from': mailing.email_from,
'reply_to': mailing.reply_to,
'email_to': test_mail,
'subject': mailing.name,
'body_html': '',
'notification': True,
'mailing_id': mailing.id,
'attachment_ids': [(4, attachment.id) for attachment in mailing.attachment_ids],
}
mail_mail_obj = Mail.browse(cr, uid, Mail.create(cr, uid, mail_values, context=context), context=context)
unsubscribe_url = Mail._get_unsubscribe_url(cr, uid, mail_mail_obj, test_mail, context=context)
html_version_url = Mail._get_html_version_url(cr, uid, mail_mail_obj, test_mail, context=context)
body = mailing.body_html.replace('__UNSUBSCRIBE_URL__', unsubscribe_url)
body = mailing.body_html.replace('__HTML_VERSION_URL__', html_version_url)
Mail.write(cr, uid, mail_mail_obj.id, {'body_html': mailing.body_html}, context=context)
mail_ids.append(mail_mail_obj.id)
Mail.send(cr, uid, mail_ids, context=context)
self.pool['mail.mass_mailing'].write(cr, uid, [mailing.id], {'state': 'test'}, context=context)
return True
#class MassMailing(osv.Model): #class MassMailing(osv.Model):
#_name = "mail.mass_mailing" #_name = "mail.mass_mailing"

Binary file not shown.

View File

@ -16,7 +16,7 @@
<div id="header"> <div id="header">
<p style="font-family: Arial,Helvetica,sans-serif; font-size: 11px; color: rgb(145, 145, 145); text-align: center;"> <p style="font-family: Arial,Helvetica,sans-serif; font-size: 11px; color: rgb(145, 145, 145); text-align: center;">
If you can't see this newsletter properly, If you can't see this newsletter properly,
<a href="/newsletter/html_version_${ctx['params']['id']}" style="color: rgb(246, 170, 66); text-decoration: underline;">click here</a></p> <a href="__HTML_VERSION_URL__" style="color: rgb(246, 170, 66); text-decoration: underline;">click here</a></p>
<table style="background-color: rgb(244, 244, 244);" align="center" border="0" cellpadding="0" cellspacing="0" width="640"> <table style="background-color: rgb(244, 244, 244);" align="center" border="0" cellpadding="0" cellspacing="0" width="640">
<tbody> <tbody>
<tr> <tr>
@ -336,7 +336,7 @@
© Groupe URD - La Fontaine des Marins - 26170 PLAISIANS - Tel :+33 (0)4 © Groupe URD - La Fontaine des Marins - 26170 PLAISIANS - Tel :+33 (0)4
75 28 29 35 - <a href="http://www.urd.org/" style="color: rgb(246, 170, 66); text-decoration: underline;">www.urd.org</a> 75 28 29 35 - <a href="http://www.urd.org/" style="color: rgb(246, 170, 66); text-decoration: underline;">www.urd.org</a>
<br> <br>
<a href="/mail/mailing/${ctx['params']['id']}/unsubscribe?res_id=${object.id}&amp;db=groupeurd&amp;email=${object.email}" style="color: rgb(246, 170, 66); text-decoration: underline;">Unsubscribe</a></p> <a href="__UNSUBSCRIBE_URL__" style="color: rgb(246, 170, 66); text-decoration: underline;">Unsubscribe</a></p>
</div> </div>

View File

@ -16,7 +16,7 @@
<div id="header"> <div id="header">
<p style="font-family: Arial,Helvetica,sans-serif; font-size: 11px; color: rgb(145, 145, 145); text-align: center;"> <p style="font-family: Arial,Helvetica,sans-serif; font-size: 11px; color: rgb(145, 145, 145); text-align: center;">
Si cet email ne s'affiche pas correctement, vous pouvez le visualiser Si cet email ne s'affiche pas correctement, vous pouvez le visualiser
grâce à <a href="/newsletter/html_version_${ctx['params']['id']}" style="color: rgb(246, 170, 66); text-decoration: underline;">ce grâce à <a href="__HTML_VERSION_URL__" style="color: rgb(246, 170, 66); text-decoration: underline;">ce
lien</a></p> lien</a></p>
<table style="background-color: rgb(244, 244, 244);" align="center" border="0" cellpadding="0" cellspacing="0" width="640"> <table style="background-color: rgb(244, 244, 244);" align="center" border="0" cellpadding="0" cellspacing="0" width="640">
<tbody> <tbody>
@ -347,7 +347,7 @@
© Groupe URD - La Fontaine des Marins - 26170 PLAISIANS - Tel :+33 (0)4 © Groupe URD - La Fontaine des Marins - 26170 PLAISIANS - Tel :+33 (0)4
75 28 29 35 - <a href="http://www.urd.org/" style="color: rgb(246, 170, 66); text-decoration: underline;">www.urd.org</a> 75 28 29 35 - <a href="http://www.urd.org/" style="color: rgb(246, 170, 66); text-decoration: underline;">www.urd.org</a>
<br> <br>
<a href="/mail/mailing/${ctx['params']['id']}/unsubscribe?res_id=${object.id}&amp;db=groupeurd&amp;email=${object.email}" style="color: rgb(246, 170, 66); text-decoration: underline;">Se désinscrire</a></p> <a href="__UNSUBSCRIBE_URL__" style="color: rgb(246, 170, 66); text-decoration: underline;">Se désinscrire</a></p>
</div> </div>