From version 11.3
To version < 12.1
edited by Manuel Smeria
on 2016/11/17 15:43
Change comment: fixed broken link

Summary

Details

Page properties
Parent
... ... @@ -1,0 +1,1 @@
1 +Extension.WebHome
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.XWikiGuest
1 +xwiki:XWiki.ManuelSmeria
Tags
... ... @@ -1,0 +1,1 @@
1 +mail|administration
Content
EXOExtensionCode.ExtensionClass[0]
ExtensionCode.ExtensionClass[0]
Description
... ... @@ -1,0 +1,73 @@
1 +{{warning}}
2 +This is a snippet using the old MailSender plugin which has been superseded by the new [[extensions:Extension.Mail Sender API]].
3 +
4 +Here's an example using the new Mail Sender API (will only work with version 6.2.5+):
5 +
6 +{{code}}
7 +{{velocity}}
8 +#set ($message = $services.mailsender.createMessage("[email protected]", "subject"))
9 +#set ($discard = $message.addPart("text/plain", "text content"))
10 +#set ($result = $services.mailsender.send($message))
11 +## Check if the message was created properly and if we have permissions to send emails
12 +#if ($services.mailsender.lastError)
13 + {{error}}$exceptiontool.getStackTrace($services.mailsender.lastError){{/error}}
14 +#end
15 +## Check if the mail we tried to send has failed to be sent
16 +#set ($statuses = $result.statusResult.getByState('FAILED'))
17 +#if ($statuses.hasNext())
18 + {{error}}Error: $statuses.next().error{{/error}}
19 +#end
20 +{{/velocity}}
21 +{{/code}}
22 +
23 +Note that this snippet doesn't store mail status results. If you wish to do that you should use instead:
24 +
25 +{{code}}
26 +#set ($result = $services.mailsender.send([$message], 'database'))
27 +{{/code}}
28 +{{/warning}}
29 +
30 +Restricted to admins.
31 +
32 +{{code}}
33 +{{velocity}}
34 +#if($xwiki.hasAccessLevel('admin'))
35 +#if("$!{request.action}" == 'send_mail' && "$!{request.lastname}" == '')
36 + ## Check submission and honey pot.
37 + #if("$!request.recipient" != '' && "$!request.subject" != '')
38 + #set($result = $xwiki.mailsender.sendTextMessage("[email protected]", $request.recipient, $request.subject, "$!request.message"))
39 + #if($result == -1)
40 + {{error}}A problem occurred while sending the mail: $context.error{{/error}}
41 + #else
42 + {{info}}Everything went OK.{{/info}}
43 + #end
44 + #else
45 + {{error}}Please specify at least a recipient and a subject{{/error}}
46 + #end
47 +#end
48 +
49 +{{html wiki=true}}
50 +<form action="" method="post">
51 + <input name="action" value="send_mail" type="hidden" />
52 + ## this is a honey-pot hidden text field hat hopefully robots will not leave empty
53 + <div class="hidden">
54 + <input name="lastname" type="text" />
55 + </div>
56 + <fieldset>
57 + **TO:**<br />
58 + <input type="text" name="recipient" /><br />
59 + **SUBJECT:**<br />
60 + <input type="text" name="subject" /><br />
61 + **MESSAGE:**<br />
62 + <textarea name="message" style="width:99%;" rows=10>Your test message here.</textarea>
63 + </fieldset>
64 + <div>
65 + <span class="buttonwrapper"><input type="submit" class="button" value="Send" /></span>
66 + </div>
67 +</form>
68 +{{/html}}
69 +#else
70 +{{error}}Oops. Area restricted to Admins, sorry.{{/error}}
71 +#end
72 +{{/velocity}}
73 +{{/code}}
Type
... ... @@ -1,0 +1,1 @@
1 +snippet
Only Custom Installation instructions
... ... @@ -1,0 +1,1 @@
1 +No
Installable with Extension Manager
... ... @@ -1,0 +1,1 @@
1 +No
Summary
... ... @@ -1,0 +1,1 @@
1 +A quick UI to verify a SMTP setup, that allows to send easily test emails
License Name
... ... @@ -1,0 +1,1 @@
1 +GNU Lesser General Public License 2.1
Name
... ... @@ -1,0 +1,1 @@
1 +Test Mail
contributors
... ... @@ -1,0 +1,1 @@
1 +Jerome Velociter
Authors
... ... @@ -1,0 +1,1 @@
1 +xwiki:XWiki.jvelociter
supported
... ... @@ -1,0 +1,1 @@
1 +0

null

cogA quick UI to verify a SMTP setup, that allows to send easily test emails
Developed by

Jerome

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

This is a snippet using the old MailSender plugin which has been superseded by the new Mail Sender API.

Here's an example using the new Mail Sender API (will only work with version 6.2.5+):

{{velocity}}
#set ($message = $services.mailsender.createMessage("[email protected]", "subject"))
#set ($discard = $message.addPart("text/plain", "text content"))
#set ($result = $services.mailsender.send($message))
## Check if the message was created properly and if we have permissions to send emails
#if ($services.mailsender.lastError)
  {{error}}$exceptiontool.getStackTrace($services.mailsender.lastError){{/error}}
#end
## Check if the mail we tried to send has failed to be sent
#set ($statuses = $result.statusResult.getByState('FAILED'))
#if ($statuses.hasNext())
  {{error}}Error: $statuses.next().error{{/error}}
#end
{{/velocity}}

Note that this snippet doesn't store mail status results. If you wish to do that you should use instead:

#set ($result = $services.mailsender.send([$message], 'database'))

Restricted to admins.

{{velocity}}
#if($xwiki.hasAccessLevel('admin'))
#if("$!{request.action}" == 'send_mail' && "$!{request.lastname}" == '')
  ## Check submission and honey pot.
  #if("$!request.recipient" != '' && "$!request.subject" != '')
    #set($result = $xwiki.mailsender.sendTextMessage("[email protected]", $request.recipient, $request.subject, "$!request.message"))
    #if($result == -1)
    {{error}}A problem occurred while sending the mail: $context.error{{/error}}
    #else
    {{info}}Everything went OK.{{/info}}
    #end
  #else
    {{error}}Please specify at least a recipient and a subject{{/error}}
  #end
#end

{{html wiki=true}}
<form action="" method="post">
 <input name="action" value="send_mail" type="hidden" />
  ## this is a honey-pot hidden text field hat hopefully robots will not leave empty
 <div class="hidden">
 <input name="lastname" type="text" />
 div>
 <fieldset>
   **TO:**<br />
   <input type="text" name="recipient" /><br />
   **SUBJECT:**<br />
   <input type="text" name="subject" /><br />
   **MESSAGE:**<br />
   <textarea name="message" style="width:99%;" rows=10>Your test message here.textarea>
 fieldset>
 <div>
   <span class="buttonwrapper"><input type="submit" class="button" value="Send" />span>
 div>
form>
{{/html}}
#else
{{error}}Oops. Area restricted to Admins, sorry.{{/error}}
#end
{{/velocity}}

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Get Connected