Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5_rtl_support
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Romain Courteaud
erp5_rtl_support
Commits
d382489f
Commit
d382489f
authored
Mar 31, 2017
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
base/crm: support sending emails with arbitrary headers
parent
88d40b40
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
7 deletions
+50
-7
bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Base_createMailMessageAsString.py
.../portal_skins/erp5_base/Base_createMailMessageAsString.py
+22
-1
bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Base_createMailMessageAsString.xml
...portal_skins/erp5_base/Base_createMailMessageAsString.xml
+1
-1
bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Entity_sendEmail.py
...inTemplateItem/portal_skins/erp5_base/Entity_sendEmail.py
+6
-2
bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/MailMessage_send.py
...inTemplateItem/portal_skins/erp5_base/MailMessage_send.py
+6
-2
bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/MailMessage_send.xml
...nTemplateItem/portal_skins/erp5_base/MailMessage_send.xml
+1
-1
product/ERP5/tests/testCRM.py
product/ERP5/tests/testCRM.py
+14
-0
No files found.
bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Base_createMailMessageAsString.py
View file @
d382489f
"""Build a mail message
* from_url: the "from" address as UTF-8 encoded string
* to_url: the "to" header as UTF-8 encoded string
* subject: the subject of the message as UTF-8 encoded string
* body: body of the message as UTF-8 encoded string
* content_type: mime type of this message, can be text/html for
HTML message or anything else for text/plain message.
* attachment_list: a list of attachement mapping in format:
- mime_type: mime type of thsi attachement
- content: file content of the attachement, as a string
- name: displayed name of this attachements
* embedded_file_list: a list of ERP5 File to use as attachments.
* extra_header_dict: additional email headers
Notes: for from_url and to_url, we should use email.utils.formataddr
"""
if
extra_header_dict
is
None
:
extra_header_dict
=
{}
if
content_type
==
'text/html'
:
mail_template
=
context
.
Event_viewHtmlMimeMessage
else
:
...
...
@@ -20,7 +40,8 @@ multipart = mail_template.as_message(mfrom=from_url,
mto
=
to_url
,
subject
=
subject
,
body
=
body
,
encoding
=
'utf-8'
)
encoding
=
'utf-8'
,
headers
=
extra_header_dict
)
for
attachment_dict
in
attachment_list
:
multipart
.
add_file
(
data
=
attachment_dict
[
'content'
],
content_type
=
attachment_dict
[
'mime_type'
],
...
...
bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Base_createMailMessageAsString.xml
View file @
d382489f
...
...
@@ -50,7 +50,7 @@
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
from_url, to_url, subject, body, content_type, attachment_list=[], embedded_file_list=[]
</string>
</value>
<value>
<string>
from_url, to_url, subject, body, content_type, attachment_list=[], embedded_file_list=[]
, extra_header_dict=None
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
...
...
bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Entity_sendEmail.py
View file @
d382489f
...
...
@@ -17,12 +17,16 @@ to_url = formataddr((context.hasTitle() and context.getTitle(), context.getDefau
document_type_list
=
list
(
event
.
getPortalEmbeddedDocumentTypeList
())
+
list
(
event
.
getPortalDocumentTypeList
())
embedded_file_list
=
event
.
getAggregateValueList
(
portal_type
=
document_type_list
)
extra_header_dict
=
kw
.
get
(
'extra_header_dict'
)
or
{}
content_type
=
event
.
getContentType
()
mail_message
=
portal
.
Base_createMailMessageAsString
(
from_url
,
mail_message
=
portal
.
Base_createMailMessageAsString
(
from_url
,
to_url
,
subject
,
body
,
content_type
,
embedded_file_list
=
embedded_file_list
)
embedded_file_list
=
embedded_file_list
,
extra_header_dict
=
extra_header_dict
)
event
.
sendMailHostMessage
(
mail_message
)
bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/MailMessage_send.py
View file @
d382489f
...
...
@@ -70,12 +70,14 @@ if download or not use_activity:
content_type
=
context
.
getContentType
()
mail_message
=
context
.
Base_createMailMessageAsString
(
from_url
,
mail_message
=
context
.
Base_createMailMessageAsString
(
from_url
,
to_url
,
subject
,
body
,
content_type
,
embedded_file_list
=
embedded_file_list
)
embedded_file_list
=
embedded_file_list
,
extra_header_dict
=
extra_header_dict
)
if
not
use_activity
:
context
.
activate
(
activity
=
'SQLQueue'
).
sendMailHostMessage
(
mail_message
)
...
...
@@ -83,6 +85,8 @@ if download or not use_activity:
if
use_activity
:
method_kw
=
dict
(
event_relative_url
=
context
.
getRelativeUrl
(),
from_url
=
from_url
)
if
extra_header_dict
:
method_kw
[
'extra_header_dict'
]
=
extra_header_dict
context
.
activate
(
after_path_and_method_id
=
((
context
.
getPath
(),),
(
'immediateReindexObject'
,
'recursiveImmediateReindexObject'
))).
MailMessage_sendByActivity
(
...
...
bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/MailMessage_send.xml
View file @
d382489f
...
...
@@ -50,7 +50,7 @@
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
from_url=None, to_url=None, reply_url=None, subject=None, body=None, attachment_format=None, attachment_list=None, download=None, **kw
</string>
</value>
<value>
<string>
from_url=None, to_url=None, reply_url=None, subject=None, body=None, attachment_format=None, attachment_list=None, download=None,
extra_header_dict=None,
**kw
</string>
</value>
</item>
<item>
<key>
<string>
_proxy_roles
</string>
</key>
...
...
product/ERP5/tests/testCRM.py
View file @
d382489f
...
...
@@ -1852,6 +1852,20 @@ class TestCRMMailSend(BaseTestCRM):
self
.
assertEqual
(
'FG ER <eee@eee.com>'
,
from_url
)
self
.
assertEqual
([
'Expert User <expert@in24.test>'
],
to_url
)
def
test_MailMessage_send_extra_headers
(
self
):
"""Test sending message with extra headers
"""
mail_message
=
self
.
portal
.
event_module
.
newContent
(
portal_type
=
"Mail Message"
,
source
=
'person_module/me'
,
destination
=
'person_module/recipient'
)
mail_message
.
send
(
extra_header_dict
=
{
"X-test-header"
:
"test"
})
self
.
tic
()
(
from_url
,
to_url
,
last_message
,),
=
self
.
portal
.
MailHost
.
_message_list
message
=
message_from_string
(
last_message
)
self
.
assertEqual
(
"test"
,
message
.
get
(
"X-test-header"
))
def
test_suite
():
suite
=
unittest
.
TestSuite
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment