Commit 82a896cc authored by Jérome Perrin's avatar Jérome Perrin

make it possible to add extra email headers


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15894 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3104706f
...@@ -142,7 +142,7 @@ class Url(Coordinate, Base, UrlMixIn): ...@@ -142,7 +142,7 @@ class Url(Coordinate, Base, UrlMixIn):
security.declareProtected(Permissions.UseMailhostServices, 'send') security.declareProtected(Permissions.UseMailhostServices, 'send')
def send(self, from_url=None, to_url=None, msg=None, def send(self, from_url=None, to_url=None, msg=None,
subject=None, attachment_list=None): subject=None, attachment_list=None, extra_headers=None):
""" """
This method was previously named 'SendMail' and is used to send email This method was previously named 'SendMail' and is used to send email
...@@ -150,6 +150,8 @@ class Url(Coordinate, Base, UrlMixIn): ...@@ -150,6 +150,8 @@ class Url(Coordinate, Base, UrlMixIn):
- name : name of the attachment, - name : name of the attachment,
- content: data of the attachment - content: data of the attachment
- mime_type: mime-type corresponding to the attachment - mime_type: mime-type corresponding to the attachment
* extra_headers is a dictionnary of custom headers to add to the email.
"X-" prefix is automatically added to those headers.
""" """
# get the mailhost object # get the mailhost object
mailhost = getattr(self.getPortalObject(), 'MailHost', None) mailhost = getattr(self.getPortalObject(), 'MailHost', None)
...@@ -174,6 +176,10 @@ class Url(Coordinate, Base, UrlMixIn): ...@@ -174,6 +176,10 @@ class Url(Coordinate, Base, UrlMixIn):
"can not handle multi-part messages!\n" "can not handle multi-part messages!\n"
message.attach(MIMEText(msg, _charset='utf-8')) message.attach(MIMEText(msg, _charset='utf-8'))
if extra_headers:
for k, v in extra_headers.items():
message.add_header('X-%s' % k, v)
message.add_header('Subject', message.add_header('Subject',
make_header([(subject, 'utf-8')]).encode()) make_header([(subject, 'utf-8')]).encode())
message.add_header('From', from_url) message.add_header('From', from_url)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment