Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Force sender email for all platform mails

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
mailtemplate
8 Respuestas
24924 Vistas
Avatar
Atl Sup

Hi!

I would like to force a special e-mail address as sender for every e-mail that will be sent from Odoo.

For instance, notifications emails for waiting for approval timesheets are sent from the user's mail. Because of our mail server limitations, those mails aren't sent (they appear in red in mails list in Odoo admin panel). How to force sending all those mails from one single e-mail address?

I tried editing "Notification Email" template ("From" field), but this does not work.


Thank you for your help.

1
Avatar
Descartar
Avatar
Victor Lopes
Mejor respuesta

Hi there!


I know this is an old post, but since there are still people interested in this, I had the same issue recently.

Odoo is in general prepared to send e-mails using only the "author's" address as sender (From), and then use a "catchall" reply-to address in order to route back the answers (when someone replies to its notifications).

The fact that you apparently can't configure Odoo to use a fixed sender for all outbound e-mails is kind of unreasonable, to say least. Because e-mail servers like Microsoft Exchange will, by default, only allow users to send through their own accounts. Not to mention that a fixed sender will be a much more simple solution and it would be nice to have a choice in this matter. But, as a community user I'm so happy that Odoo is available open source that this won't bother me much.


So as of now you have basically two options:


  1.  Configure you mail server to allow relay from your Odoo server. On Exchange Server, for example, this can be done by adding a custom Receive Connector with "Anonymous / Externally secured" authentication. You can find out more here: https://technet.microsoft.com/en-us/library/mt668454%28v=exchg.160%29.aspx?f=255&MSPPError=-2147217396  and  here: https://practical365.com/exchange-server/how-to-configure-a-relay-connector-for-exchange-server-2010/

  2. Modify the mail_mail.py and the ir_mail_server.py modules in Odoo in order to hardcode a fixed e-mail address that will be used for all outbound e-mail messages, which was the most effective solution for me.


So, for this second option, here is how to do it on a Odoo 10 installation:


A little background


If you try to send replies from within your Odoo records (Leads, Purchase orders, etc.) and your mail server doesn't allow relay, you will see messages like these in your logs (/var/log/odoo  - file: odoo-server):

2017-11-23 11:54:56,597 3848 odoo.addons.base.ir.ir_mail_server: Mail delivery failed via SMTP server 'YOURMAILSERVER'.
SMTPDataError: 550
5.7.1 Client does not have permissions to send as this sender
2017-11-23 11:54:56,598 3848 ERROR odoo.addons.mail.models.mail_mail: failed sending mail (id: 16) due to Mail Delivery Failed
Mail delivery failed via SMTP server 'YOURMAILSERVER'.
SMTPDataError: 550
5.7.1 Client does not have permissions to send as this sender
Traceback (most recent call last):
  File "/odoo/odoo-server/addons/mail/models/mail_mail.py", line 278, in send
    res = IrMailServer.send_email(msg, mail_server_id=mail.mail_server_id.id)
  File "/odoo/odoo-server/odoo/addons/base/ir/ir_mail_server.py", line 464, in send_email
    raise MailDeliveryException(_("Mail Delivery Failed"), msg)


The changes


Alter the file /odoo/odoo-server/addons/mail/models/mail_mail.py:


Inside the function "send" (look for "def send(" ), around line 278, you will find this block:


                # build an RFC2822 email.message.Message object and send it without queuing 
                res = None
                for email in email_list:
                    msg = IrMailServer.build_email(
                        email_from=mail.email_from,
                        email_to=email.get('email_to'),
                        subject=mail.subject,
                        [...some other stuff...]
                        headers=headers)
                    try:
                        res = IrMailServer.send_email(msg, mail_server_id=mail.mail_server_id.id)


Change the line email_from=mail.email_from . Replace "mail.email_from" by an e-mail address of your choice, like 'contact@mycompany.com'. You can even use a more fancy formatting here, to include a sender name, like 'My Sales Department <sales@mycompany.com>'.

It should look like this: email_from='My Company <contact@mycompany.com>'

Don't forget the single quotes.


Then, alter the file /odoo/odoo-server/odoo/addons/base/ir/ir_mail_server.py


Inside the function "send_email" (look for "def send_email"), around line 396 you will find:


        smtp_from = from_rfc2822[-1]
        email_to = message['To']
        email_cc = message['Cc']
        email_bcc = message['Bcc']


Change smtp_from = from_rfc2822[-1] . Replace "from_rfc2822[-1]" by your address. Here you have to use just the e-mail address, like 'contact@mycompany.com'  . Don't include < >, spaces nor any non-ASCII characters.

It should look like: smtp_from = 'contact@mycompany.com'


That's it. After saving these files, restart Odoo's service (sudo service odoo-server restart) and try again.

This was tested on an Odoo 10 installation, on a Ubuntu Server 16.04 (Xenial).  I have installed it using this great script from Yenthe: https://www.odoo.yenthevg.com/installing-odoo-10-ubuntu-16-04


Some final considerations:

  • While editing these python files, don't mess up with the indentation. Python has specific text indentation requirements. 
    More on this: https://stackoverflow.com/questions/1016814/what-to-do-with-unexpected-indent-in-python

  • Don't forget to set the "Alias Domain" and to configure the "catchall" address. Please take a look at these instructions: https://www.odoo.com/documentation/user/11.0/discuss/email_servers.html
    If you don't set the Alias Domain, it's likely that Odoo will populate the "reply-to" field with the author's e-mail, and this will lead to an even bigger mess.

  • If you choose the first option (configuring relay on your mail server), don't forget that you can't send e-mails using sender domains that you don't own. I mean, you should only allow your internal users to use Odoo with your own e-mail accounts. Don't let anyone use addresses like "mypersonal@gmail.com", because this will cause your mail server to try sending messages as it owned the "gmail.com" domain, whenever a user like this reply on a record, for example.


I hope this helps somebody.

Cheers,


Victor Lopes.

 

4
Avatar
Descartar
Avatar
Alixsander Haj Saw
Mejor respuesta

A simple solution using official documentation. Tested on Odoo 17.

  1. Turn on developer mode.
  2. Go to Settings ‣ Technical ‣ Parameters ‣ System Parameters.
  3. Add one system parameter from the following list:
    • To use the same “From” address for all outgoing messages, use the key mail.force.smtp.from and set that address as value (such as outgoing@mycompany.example.com).

You might not have the "mail.force.smtp.from " field, just create one and set its value to the email you want to force.

The official odoo documentation

1
Avatar
Descartar
Victor Lopes

Thanks. It's great to see that the issue has been noticed and now there is an official way to do it.

Avatar
Carlos Mendoza
Mejor respuesta

So, you could also make an automated action (Technical - Automated Actions) similar to this:

Just change the model to what you need:


1
Avatar
Descartar
Daniel Buchsbaum

That's actually a very good and underrated idea!

Avatar
Jose Gpe Osuna
Mejor respuesta

When you don't have manager rights on the email server, what you could do is to inherit Odoo's send_email() method in order to force all the email parameters to be the same as the email login user.

I was having this message

SMTPDataError: 550
5.7.1 Client does not have permissions to send as this sender

This is the code for Odoo 11

class IrMailServer(models.Model):
_inherit = "ir.mail_server"

@api.model
def send_email(self, message, mail_server_id=None, smtp_server=None, smtp_port=None,
smtp_user=None, smtp_password=None, smtp_encryption=None, smtp_debug=False,
smtp_session=None):

""" Force 'Return-Path' and 'Form' email parameters with smtp_user data,
Message error:
SMTPDataError: 550
5.7.1 Client does not have permissions to send as this sender
"""

# Get SMTP Server Details from Mail Server
mail_server = None
if mail_server_id:
mail_server = self.sudo().browse(mail_server_id)
elif not smtp_server:
mail_server_ids = self.sudo().search([], order='sequence', limit=1)
if mail_server_ids:
mail_server = mail_server_ids[0]

# if mail_serveris set, take smtp_user
if mail_server:
smtp_user = mail_server.smtp_user
if '@' not in smtp_user and mail_server.smtp_host:
# If smtp_user doesn't fit an email pattern, take domain from smtp_host
smtp_user += '@' + mail_server.smtp_host.partition('.')[2]

# Change email parameters
if 'Return-Path' in message:
message.replace_header('Return-Path', smtp_user)
else:
message['Return-Path'] = smtp_user

if 'From' in message:
message.replace_header('From', smtp_user)
else:
message['From'] = smtp_user

# Super to send_email()
res = super(IrMailServer, self).send_email(message, mail_server_id, smtp_server, smtp_port,
smtp_user, smtp_password, smtp_encryption, smtp_debug, smtp_session)
return res

It worked for me. I hope it helps.


0
Avatar
Descartar
Avatar
Universidad Católica del Uruguay
Mejor respuesta

Hi,

I have the same issue, any solution?

Thanks!

0
Avatar
Descartar
Avatar
rory
Mejor respuesta

In addition to Victor Lopes comment.

Odoo v12

One additional line to change in the mail_message.py file

In line 31 in the def _get_default_from 

change the line return formataddr((self.env.user.name, self.env.user.email))
to return formataddr((self.env.user.name, 'Insert email address'))

0
Avatar
Descartar
Avatar
Atl Sup
Autor Mejor respuesta

Has anyone some more information about this issue?

0
Avatar
Descartar
Avatar
Datrepack
Mejor respuesta

@Victor Lopes

Amazing work ! I've been stuck with this problem from days. It resolved it in minutes with your Option 2 ! Still work on Odoo V12

Tank you !

0
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
Changing Position of Email: Customer Adress on Sale/Invoice
mail template
Avatar
Avatar
1
sept 21
4601
Bounce address when sending some mail from mail.template
mail template
Avatar
0
nov 20
4285
How to create email template using python
mail template
Avatar
Avatar
Avatar
Avatar
Avatar
7
sept 19
36856
Cannot save e-mail templates
mail template
Avatar
Avatar
1
mar 15
7550
Odoo 12 enterprise - Custom mail notification layout, name of custom template not found
mail layout template
Avatar
0
nov 19
5815
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now