Skip to content

Commit

Permalink
[ADD] mail_outbound_static: Forward port #1044
Browse files Browse the repository at this point in the history
Signed-off-by hbrunn
  • Loading branch information
OCA-git-bot authored and hbrunn committed Jan 9, 2025
1 parent b9e124e commit 6ea9a17
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 2 deletions.
6 changes: 6 additions & 0 deletions mail_outbound_static/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ being appended into the proper Sender header instead. To accomplish this we:
smtp_from and smtp_whitelist_domain values will be used if there is not mail
server configured in the system.

* If your server doesn't support catchall too, you can activate `Reply To The Same Address`
flag, so 'Reply-To' in your message will be the same as 'From'.

**Table of contents**

.. contents::
Expand All @@ -64,6 +67,7 @@ Usage
* Navigate to an Outbound Email Server
* Set the `Email From` option to an email address
* Set the `Domain Whitelist` option with the domain whitelist
* Set the `Reply to the same address` option to modify 'Reply-To' message field

Bug Tracker
===========
Expand All @@ -81,6 +85,7 @@ Credits
Authors
~~~~~~~

* Solvti sp. z o.o.
* brain-tec AG
* LasLabs
* Adhoc SA
Expand All @@ -97,6 +102,7 @@ Contributors
* `Quartile <https://www.quartile.co>`__:

* Yoshi Tashiro
* Sergei Ruzki <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
5 changes: 4 additions & 1 deletion mail_outbound_static/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"version": "16.0.1.0.2",
"category": "Discuss",
"website": "https://github.com/OCA/social",
"author": "brain-tec AG, LasLabs, Adhoc SA, Odoo Community Association (OCA)",
"author": "Solvti sp. z o.o., "
"brain-tec AG, "
"LasLabs, Adhoc SA, "
"Odoo Community Association (OCA)",
"license": "LGPL-3",
"application": False,
"installable": True,
Expand Down
12 changes: 12 additions & 0 deletions mail_outbound_static/i18n/mail_outbound_static.pot
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ msgstr ""
msgid "Not a valid Email From"
msgstr ""

#. module: mail_outbound_static
#: model:ir.model.fields,field_description:mail_outbound_static.field_ir_mail_server__reply_to_the_same_address
msgid "Reply To The Same Address"
msgstr ""

#. module: mail_outbound_static
#: model:ir.model.fields,help:mail_outbound_static.field_ir_mail_server__reply_to_the_same_address
msgid ""
"If you have no catchall support for this server and will activate "
"this option, Reply-To address will be the same as From address."
msgstr ""

#. module: mail_outbound_static
#: model:ir.model.fields,help:mail_outbound_static.field_ir_mail_server__smtp_from
msgid ""
Expand Down
12 changes: 12 additions & 0 deletions mail_outbound_static/models/ir_mail_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class IrMailServer(models.Model):
" match with the domain whitelist."
)

reply_to_the_same_address = fields.Boolean(
help="If you have no catchall support for this server and will activate "
"this option, Reply-To address will be the same as From address."
)

@api.constrains("domain_whitelist")
def check_valid_domain_whitelist(self):
if self.domain_whitelist:
Expand Down Expand Up @@ -93,6 +98,13 @@ def _prepare_email_message(self, message, smtp_session):
message.replace_header("Return-Path", email_from)
else:
message.add_header("Return-Path", email_from)
# If reply to the same address is True,
# Reply-To header field should have the same as sender address
if mail_server.reply_to_the_same_address:
message.replace_header("Reply-To", email_from) if message.get(
"Reply-To"
) else message.add_header("Reply-To", email_from)

return smtp_from, smtp_to_list, message

@api.model
Expand Down
1 change: 1 addition & 0 deletions mail_outbound_static/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
* `Quartile <https://www.quartile.co>`__:

* Yoshi Tashiro
* Sergei Ruzki <[email protected]>
3 changes: 3 additions & 0 deletions mail_outbound_static/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ being appended into the proper Sender header instead. To accomplish this we:
* Add compatibility to define the smtp information in Odoo config file. Both
smtp_from and smtp_whitelist_domain values will be used if there is not mail
server configured in the system.

* If your server doesn't support catchall too, you can activate `Reply To The Same Address`
flag, so 'Reply-To' in your message will be the same as 'From'.
1 change: 1 addition & 0 deletions mail_outbound_static/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Navigate to an Outbound Email Server
* Set the `Email From` option to an email address
* Set the `Domain Whitelist` option with the domain whitelist
* Set the `Reply to the same address` option to modify 'Reply-To' message field
6 changes: 5 additions & 1 deletion mail_outbound_static/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -392,6 +391,8 @@ <h1 class="title">Mail Outbound Static</h1>
<li>Add compatibility to define the smtp information in Odoo config file. Both
smtp_from and smtp_whitelist_domain values will be used if there is not mail
server configured in the system.</li>
<li>If your server doesn’t support catchall too, you can activate <cite>Reply To The Same Address</cite>
flag, so ‘Reply-To’ in your message will be the same as ‘From’.</li>
</ul>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand All @@ -412,6 +413,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<li>Navigate to an Outbound Email Server</li>
<li>Set the <cite>Email From</cite> option to an email address</li>
<li>Set the <cite>Domain Whitelist</cite> option with the domain whitelist</li>
<li>Set the <cite>Reply to the same address</cite> option to modify ‘Reply-To’ message field</li>
</ul>
</div>
<div class="section" id="bug-tracker">
Expand All @@ -427,6 +429,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>Solvti sp. z o.o.</li>
<li>brain-tec AG</li>
<li>LasLabs</li>
<li>Adhoc SA</li>
Expand All @@ -445,6 +448,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Yoshi Tashiro</li>
</ul>
</li>
<li>Sergei Ruzki &lt;<a class="reference external" href="mailto:sergei.ruzki&#64;gmail.com">sergei.ruzki&#64;gmail.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
21 changes: 21 additions & 0 deletions mail_outbound_static/tests/test_ir_mail_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,24 @@ def test_10_not_valid_smtp_from(self):
mail_server.smtp_from = "."

mail_server.smtp_from = "[email protected]"

def test_11_from_outgoing_server_with_catchall(self):
self._init_mail_server_domain_whilelist_based()
domain = "example.com"
email_from = "test@%s" % domain

self.message.replace_header("From", email_from)
reply_to_address = self.message["Reply-To"]
message = self._send_mail(self.message)
self.assertEqual(message["Reply-To"], reply_to_address)

def test_12_from_outgoing_server_no_catchall(self):
self._init_mail_server_domain_whilelist_based()
domain = "example.com"
email_from = "test@%s" % domain
expected_mail_server = self.mail_server_domainone

self.message.replace_header("From", email_from)
expected_mail_server.reply_to_the_same_address = True
message = self._send_mail(self.message)
self.assertEqual(message["Reply-To"], expected_mail_server.smtp_from)
4 changes: 4 additions & 0 deletions mail_outbound_static/views/ir_mail_server_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<xpath expr="//field[@name='smtp_pass']" position="after">
<field name="domain_whitelist" />
<field name="smtp_from" widget="email" />
<field
name="reply_to_the_same_address"
attrs="{'invisible': [('smtp_from', '=', False)]}"
/>
</xpath>
</field>
</record>
Expand Down

0 comments on commit 6ea9a17

Please sign in to comment.