API:Emailuser
Language: | English • Deutsch • 日本語 |
---|
This page is part of the MediaWiki action API documentation. |
MediaWiki action API
- Introduction and quick start
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Searching (by title, content, coordinates...)
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Create and edit pages
- Move pages
- Merge pages
- Rollback
- Delete pages
- Restore deleted revisions
- (Un)protect pages
- (Un)block users
- (Un)watch pages
- Mark revisions of watched pages as visited
- Send email
- Patrol changes
- Import pages
- Change user group membership
- Upload files
- User options
- Tokens
- Page language
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
- Asserting
MediaWiki version: | ≥ 1.13 |
Email a user.
Contents
Token[edit]
To send an email, an email token is required. This token is equal to the edit token and the same for all recipients, but changes at every login. Email tokens can be obtained via action=tokens with type=email (MW 1.20+), or by using the following method:
Obtaining an email token
Result |
---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<query>
<pages>
<page
pageid="1"
ns="2"
title="User:Catrope"
touched="2007-09-03T20:32:21Z"
lastrevid="20"
counter="20"
length="470"
emailtoken="58b54e0bab4a1d3fd3f7653af38e75cb+\"
/>
</pages>
</query>
</api>
|
Sending email to users[edit]
You can send email to users who have a confirmed email address with action=emailuser. Sending email is subject to rate limits.
Parameters[edit]
target
: User to send email tosubject
: The subject of the messagetext
: The messagetoken
: The token obtained in the previous request. Take care to encode the+
as%2B
ccme
: If set, a copy of the email will be sent to you
Examples[edit]
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=emailuser requires POST requests; GET requests will cause an error.
Sending an email to User:Catrope
Result |
---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<emailuser result="Success" />
</api>
|
Possible errors[edit]
In addition to the usual stuff:
Code | Info |
---|---|
cantsend | You're not logged in or you don't have a confirmed email address, so you can't send email |
blockedfrommail | You have been blocked from sending email |
usermaildisabled | User email has been disabled |
notarget | You have not specified a valid target for this action |
noemail | The user has not specified a valid email address, or has chosen not to receive email from other users |
Checking emailable status[edit]
Before trying to send an email, it is recommended to check if the user is emailable first. To do this, you can execute a list query on the user (or several users at once). Here is an example using Ajax:
new mw.Api().get( {
action: 'query',
list: 'users',
ususers: mw.config.get( 'wgTitle' ),
usprop: 'emailable',
rawcontinue: ''
} ).done( function( getEmailable ) {
alert( ( getEmailable.query.users[ 0 ][ 'emailable' ] !== undefined ) ? 'emailable' : 'not emailable' );
} );
If you are testing from a client-side script, it is also possible to simply check for the existence of the t-emailuser list item:
emailable = $( '#t-emailuser' ).length ? true : false;
The following documentation is the output of Special:ApiHelp/emailuser, generated from emailuser's source code. |
action=emailuser
- This module requires read rights.
- This module requires write rights.
- This module only accepts POST requests.
- Source: MediaWiki
- License: GPL-2.0+
Email a user.
- target
-
User to send email to.
- This parameter is required.
- subject
-
Subject header.
- text
-
Mail body.
- This parameter is required.
- ccme
-
Send a copy of this mail to me.
- Type: boolean (details)
- token
-
A "csrf" token retrieved from action=query&meta=tokens
- This parameter is required.
- Send an email to user WikiSysop with the text Content.
- api.php?action=emailuser&target=WikiSysop&text=Content&token=123ABC [open in sandbox]