When using the "Test Mailing" button, a sample mail was sent to a particular mail address and a text-like unsubscribe link was added below the mail body. This link was ugly, ununderstandable and useless as it is test mailing anyway. To add unsubscribe links to your mail body, use the footer blocks which contain this kind of link (note: they are inserted by default in all mail templates).
38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models, tools
|
|
|
|
|
|
class TestMassMailing(models.TransientModel):
|
|
_name = 'mail.mass_mailing.test'
|
|
_description = 'Sample Mail Wizard'
|
|
|
|
email_to = fields.Char(string='Recipients', required=True,
|
|
help='Comma-separated list of email addresses.', default=lambda self: self.env['mail.message']._get_default_from())
|
|
mass_mailing_id = fields.Many2one('mail.mass_mailing', string='Mailing', required=True)
|
|
|
|
@api.multi
|
|
def send_mail_test(self):
|
|
self.ensure_one()
|
|
mails = self.env['mail.mail']
|
|
mailing = self.mass_mailing_id
|
|
test_emails = tools.email_split(self.email_to)
|
|
for test_mail in test_emails:
|
|
# Convert links in absolute URLs before the application of the shortener
|
|
mailing.write({'body_html': self.env['mail.template']._replace_local_links(mailing.body_html)})
|
|
mail_values = {
|
|
'email_from': mailing.email_from,
|
|
'reply_to': mailing.reply_to,
|
|
'email_to': test_mail,
|
|
'subject': mailing.name,
|
|
'body_html': mailing.body_html,
|
|
'notification': True,
|
|
'mailing_id': mailing.id,
|
|
'attachment_ids': [(4, attachment.id) for attachment in mailing.attachment_ids],
|
|
}
|
|
mail = self.env['mail.mail'].create(mail_values)
|
|
mails |= mail
|
|
mails.send()
|
|
return True
|