Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Force sender email for all platform mails

Odebírat

Get notified when there's activity on this post

This question has been flagged
mailtemplate
8 Odpovědi
24950 Zobrazení
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
Zrušit
Avatar
Victor Lopes
Nejlepší odpověď

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
Zrušit
Avatar
Alixsander Haj Saw
Nejlepší odpověď

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
Zrušit
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
Nejlepší odpověď

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

Just change the model to what you need:


1
Avatar
Zrušit
Daniel Buchsbaum

That's actually a very good and underrated idea!

Avatar
Jose Gpe Osuna
Nejlepší odpověď

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
Zrušit
Avatar
Universidad Católica del Uruguay
Nejlepší odpověď

Hi,

I have the same issue, any solution?

Thanks!

0
Avatar
Zrušit
Avatar
rory
Nejlepší odpověď

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
Zrušit
Avatar
Atl Sup
Autor Nejlepší odpověď

Has anyone some more information about this issue?

0
Avatar
Zrušit
Avatar
Datrepack
Nejlepší odpověď

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

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Changing Position of Email: Customer Adress on Sale/Invoice
mail template
Avatar
Avatar
1
zář 21
4624
Bounce address when sending some mail from mail.template
mail template
Avatar
0
lis 20
4305
How to create email template using python
mail template
Avatar
Avatar
Avatar
Avatar
Avatar
7
zář 19
36888
Cannot save e-mail templates
mail template
Avatar
Avatar
1
bře 15
7571
Odoo 12 enterprise - Custom mail notification layout, name of custom template not found
mail layout template
Avatar
0
lis 19
5842
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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