Skip to content

Commit

Permalink
[FIX] mail_no_reply: force no reply mail in 'email_from' and 'reply_to'
Browse files Browse the repository at this point in the history
  • Loading branch information
corredato committed Oct 17, 2024
1 parent 8a52516 commit b5c990c
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions mail_no_reply/models/mail_compose_message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from odoo import api, fields, models


class MailComposeMessage(models.TransientModel):
class MailComposer(models.TransientModel):
_inherit = "mail.compose.message"

active_no_reply = fields.Boolean(string="Use no-reply email")
Expand All @@ -27,4 +27,52 @@ def create(self, vals):
if vals.get("active_no_reply") and self.env.user.company_id.email_no_reply:
vals["email_from"] = self.env.user.company_id.email_no_reply
vals["reply_to"] = self.env.user.company_id.email_no_reply
return super(MailComposeMessage, self).create(vals)
return super(MailComposer, self).create(vals)

def send_mail_message(self, auto_commit=False):
if self.active_no_reply and self.env.user.company_id.email_no_reply:
self.email_from = self.env.user.company_id.email_no_reply
self.reply_to = self.env.user.company_id.email_no_reply
message = super(MailComposer, self).send_mail_message(auto_commit=auto_commit)
if self.active_no_reply:
mail_message = self.env["mail.message"].browse(message)
mail_message.sudo().write(
{
"email_from": self.env.user.company_id.email_no_reply,
"reply_to": self.env.user.company_id.email_no_reply,
}
)
return message

def _action_send_mail(self, auto_commit=False):
result_mails_su, result_messages = super(MailComposer, self)._action_send_mail(
auto_commit=auto_commit
)
for mail in result_mails_su:
if mail.mail_template_id and mail.mail_template_id.active_no_reply:
no_reply_email = self.env.user.company_id.email_no_reply
if no_reply_email:
mail.write(
{
"email_from": no_reply_email,
"reply_to": no_reply_email,
}
)
if not self.env.context.get("mail_return_path"):
self = self.with_context(mail_return_path=no_reply_email)
if result_messages:
for message in result_messages:
if message.mail_ids:
for mail in message.mail_ids:
if (
self.active_no_reply
and self.env.user.company_id.email_no_reply
):
mail.write(
{
"email_from": self.env.user.company_id.email_no_reply,
"reply_to": self.env.user.company_id.email_no_reply,
}
)

return result_mails_su, result_messages

0 comments on commit b5c990c

Please sign in to comment.