Code source wiki de MeetingMailSender
Modifié par Vincent Massol le 2011/08/12 21:26
Masquer les derniers auteurs
author | version | line-number | content |
---|---|---|---|
1.1 | 1 | <% | |
2 | |||
3 | // Send a mail from template including an additional note | ||
4 | |||
5 | import com.xpn.xwiki.plugin.mailsender.Mail; | ||
6 | import java.util.ArrayList; | ||
7 | |||
8 | def extra = request.mailnote; | ||
9 | def toAddr = request.recipient; | ||
10 | def fromAddr = xwiki.getXWikiPreference("admin_email") | ||
11 | |||
12 | def ccAddr = null | ||
13 | def bccAddr = null | ||
14 | |||
15 | vcontext = context.get("vcontext") | ||
16 | |||
17 | // Prepare mail template context | ||
18 | |||
19 | vcontext.put("userName", request.username); | ||
20 | |||
21 | meetingDoc = xwiki.getDocument(request.meeting) | ||
22 | meeting = meetingDoc.getObject("MMCode.MeetingClass") | ||
23 | |||
24 | vcontext.put("meetingTitle", meetingDoc.title) | ||
25 | vcontext.put("meetingURL", meetingDoc.getExternalURL()) | ||
26 | |||
27 | templateDoc = xwiki.getDocument(request.template) | ||
28 | template = templateDoc.getObject("XWiki.Mail") //TODO check language | ||
29 | |||
30 | textContent = xwiki.parseContent(template.get("text")) | ||
31 | htmlContent = xwiki.parseContent(template.get("html")) | ||
32 | subject = xwiki.parseContent(template.get("subject")) | ||
33 | |||
34 | // decorate text/HTML content with extra note. | ||
35 | if (!extra.equals("")) { | ||
36 | def args = new ArrayList(); | ||
37 | args.add(xwiki.getUserName(meetingDoc.creator, false)) | ||
38 | intro = msg.get("meetings.mail.personalnote", args) | ||
39 | textContent += ("\n\n" + intro + "\n\"" + extra + "\"") | ||
40 | htmlContent += ("<br /><br />" + intro + "<br />\"" +extra + "\"<br />") | ||
41 | } | ||
42 | |||
43 | // TODO: ultimately the code below should be merged in the mailsender plugin | ||
44 | |||
45 | vcontext.put("from.name", fromAddr); | ||
46 | vcontext.put("from.address", fromAddr); | ||
47 | vcontext.put("to.name", toAddr); | ||
48 | vcontext.put("to.address", toAddr); | ||
49 | vcontext.put("to.cc", ccAddr); | ||
50 | vcontext.put("to.bcc", bccAddr); | ||
51 | vcontext.put("bounce", fromAddr); | ||
52 | |||
53 | Mail mail = new Mail(); | ||
54 | |||
55 | mail.setFrom((String) vcontext.get("from.address")); | ||
56 | mail.setTo((String) vcontext.get("to.address")); | ||
57 | mail.setCc((String) vcontext.get("to.cc")); | ||
58 | mail.setBcc((String) vcontext.get("to.bcc")); | ||
59 | mail.setSubject(subject); | ||
60 | mail.setTextPart(textContent); | ||
61 | mail.setHtmlPart(htmlContent); | ||
62 | |||
63 | try { | ||
64 | xwiki.getPlugin("mailsender").getProtectedPlugin().sendMail(mail, context.context); | ||
65 | print "<div class='infomessage'>Email envoyé avec succes à l'adresse <strong>" + toAddr + "</strong>. Vous pouvez fermer cette fenêtre.</div>" | ||
66 | } | ||
67 | catch (Exception e) { | ||
68 | print "ERROR:" + e.message | ||
69 | } | ||
70 | |||
71 | %> |