Test Mail

Last modified by Manuel Smeria on 2021/03/18 11:28

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


0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents


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+):

#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)
## 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}}

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.

#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}}
    {{info}}Everything went OK.{{/info}}
    {{error}}Please specify at least a recipient and a subject{{/error}}

{{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" />
   **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>
   <span class="buttonwrapper"><input type="submit" class="button" value="Send" /></span>
{{error}}Oops. Area restricted to Admins, sorry.{{/error}}

Get Connected