User:VirginiaBalseiro/Sandbox/API:Emailuser

POST REQUEST to email a user.

You can send email to users who have a confirmed email address with action=emailuser. Sending email is subject to rate limits.

API documentation

edit

action=emailuser

(main | emailuser)
  • This module requires read rights.
  • This module requires write rights.
  • This module only accepts POST requests.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Email a user.

Specific parameters:
Other general parameters are available.
target

User to send the email to.

This parameter is required.
subject

Subject header.

This parameter is required.
text

Email 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.
Example:
Send an email to the user WikiSysop with the text Content.
api.php?action=emailuser&target=WikiSysop&text=Content&token=123ABC [open in sandbox]


Example

edit

Notes:

  • 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.
  • token in the request above is retrieved from API:Tokens

Sending an email to User:Catrope

api.php?action=emailuser&target=Catrope&subject=Hi&text=Just%20wanted%20to%20say%20hi&token=58b54e0bab4a1d3fd3f7653af38e75cb+\ [try in ApiSandbox]

Checking emailable status

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;

POST Request

edit

/w/api.php?action=emailuser&format=json&target=Catrope&subject=Hi&text=Just%20wanted%20to%20say%20hi&token=a6aee044d51e3f44d5728bcf3db7110e5bace1c0%2B%5C

Response

edit
{
    "emailuser": {
        "result": "Success"
    }
}

Sample code

edit

Possible errors

edit

In addition to the usual stuff:

Code Info
cantsend You are not logged in, you do not have a confirmed email address, or you are not allowed to send email to other users, so you cannot 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 This user has not specified a valid email address.

This user has chosen not to receive email from other users.

Additional notes

edit

This module cannot be used as a Generator.

Prefix none
Required rights sendemail
Post only? Yes
Generated help Current
Version added
1.13