[17.0] mail_composer_cc_bcc Error on send mail with BCC
When i try to send email with mail.compose.message like that for example : ctx = { 'default_model': 'training.session', 'default_use_template': bool(template.id), 'default_template_id': template.id, 'default_composition_mode': 'comment', 'default_partner_ids': [(6, 0, self.company_id.partner_id.ids)], 'default_partner_bcc_ids': [(6, 0, bcc_partner_ids.ids)], 'default_freeze_partner_ids': True, } return { 'type': 'ir.actions.act_window', 'view_mode': 'form', 'res_model': 'mail.compose.message', 'views': [(False, 'form')], 'view_id': False, 'target': 'new', 'context': ctx, }
The outgoing server mail return this error : There may be at most 1 Bcc headers in a message
I have tried differents ways to resolve this issue but nothing work.
I think there are a problem with this addon.
@trisdoan Do you have any idea for this issue ?
The error provide from this : class IrMailServer(models.Model): _inherit = "ir.mail_server"
def _prepare_email_message(self, message, smtp_session):
"""
Define smtp_to based on context instead of To+Cc+Bcc
"""
x_odoo_bcc_value = next(
(value for key, value in message._headers if key == "X-Odoo-Bcc"), None
)
# Add Bcc field inside message to pass validation
if x_odoo_bcc_value:
message["Bcc"] = x_odoo_bcc_value
smtp_from, smtp_to_list, message = super()._prepare_email_message(
message, smtp_session
)
is_from_composer = self.env.context.get("is_from_composer", False)
if is_from_composer and self.env.context.get("recipients", False):
smtp_to = self.env.context["recipients"].pop(0)
_logger.debug("smtp_to: %s", smtp_to)
smtp_to_list = [smtp_to]
return smtp_from, smtp_to_list, message
the header already exist, so when it pass on these lines it raise the error : if x_odoo_bcc_value: message["Bcc"] = x_odoo_bcc_value
i resolve the error like this : if "Bcc" not in message: message["Bcc"] = x_odoo_bcc_value
But i'm not sure it really consistent and the best way
Hello, I am still able to send mail w/ cc/bcc via Mail Composer. Could you elaborate on the flow you did? Or any add-on you install?