Utilisation png24 transparent pour le logo de Plinn.
[Plinn.git] / profiles / photo / workflows / order_workflow / scripts / sendNotificationEmail.py
1 ## Script (Python) "sendNotificationEmail"
2 ##bind container=container
3 ##bind context=context
4 ##bind namespace=
5 ##bind script=script
6 ##bind subpath=traverse_subpath
7 ##parameters=sci
8 ##title=
9 ##
10 from Products.photoprint.utils import translate
11 _ = lambda msg : translate(msg, context)
12 portal = context.portal_url.getPortalObject()
13
14 mtool = portal.portal_membership
15
16 recipients = sci.kwargs.get('recipients', [])
17 if not recipients :
18 return []
19
20
21 MailHost = portal.MailHost
22 from quopri import encodestring
23
24 def encodeAdr(member) :
25 name = member.getMemberFullName(nameBefore=0)
26 email = member.getProperty('email')
27 qpName = encodestring(name).replace('=\n', '')
28 return '''"=?utf-8?q?%s?=" <%s>''' % (qpName, email)
29
30
31 object = sci.object
32
33 sender = mtool.getAuthenticatedMember()
34 sender = encodeAdr(sender)
35
36 recipientsFormated = map(encodeAdr, mtool.getMembers( recipients ))
37 mto = ', '.join(recipientsFormated)
38 if mto[-2:] == ', ' :
39 mto = mto[:-2]
40
41 subject = sci.kwargs.get('subject', '')
42
43 body = []
44 pr = body.append
45 pr(sci.kwargs.get('comment', ''))
46
47 pr('')
48
49 trNumber = sci.kwargs.get('tracking_number', '')
50 if trNumber :
51 pr(_('Tracking number').encode('utf-8') + ' ' + trNumber)
52
53 trUrl = sci.kwargs.get('tracking_url', '')
54 if trUrl :
55 pr(_('Tracking url').encode('utf-8') + ' ' + trUrl)
56
57 body = '\n'.join(body)
58
59
60
61 message = context.echange_mail_template( From = sender
62 , To = mto
63 , Subject = "=?utf-8?q?%s?=" % encodestring(subject).replace('=\n', '')
64 , ContentType = 'text/plain'
65 , charset = 'UTF-8'
66 , body=body
67 )
68
69
70 MailHost.send( message.encode('utf-8') )
71
72 return recipients