Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Force sender email for all platform mails

Subscriure's

Get notified when there's activity on this post

This question has been flagged
mailtemplate
8 Respostes
24941 Vistes
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
Best Answer

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
Best Answer

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
Best Answer

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
Best Answer

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
Best Answer

Hi,

I have the same issue, any solution?

Thanks!

0
Avatar
Descartar
Avatar
rory
Best Answer

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 Best Answer

Has anyone some more information about this issue?

0
Avatar
Descartar
Avatar
Datrepack
Best Answer

@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
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Changing Position of Email: Customer Adress on Sale/Invoice
mail template
Avatar
Avatar
1
de set. 21
4615
Bounce address when sending some mail from mail.template
mail template
Avatar
0
de nov. 20
4302
How to create email template using python
mail template
Avatar
Avatar
Avatar
Avatar
Avatar
7
de set. 19
36879
Cannot save e-mail templates
mail template
Avatar
Avatar
1
de març 15
7561
Odoo 12 enterprise - Custom mail notification layout, name of custom template not found
mail layout template
Avatar
0
de nov. 19
5838
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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