API:Emailuser: Difference between revisions
translation tweaks |
editing |
||
(8 intermediate revisions by 5 users not shown) | |||
Line 43: | Line 43: | ||
*{{ApiParam|subject|2=<translate><!--T:8--> The subject of the message</translate>}} |
*{{ApiParam|subject|2=<translate><!--T:8--> The subject of the message</translate>}} |
||
*{{ApiParam|text|2=<translate><!--T:9--> The message</translate>|required=1}} |
*{{ApiParam|text|2=<translate><!--T:9--> The message</translate>|required=1}} |
||
*{{ApiParam|token|2=<translate><!--T:10--> The token obtained in the previous request.</translate> <translate>Take care to encode the <tvar name=1><code>+</code></tvar> as <tvar name=2><code>%2B</code></tvar></translate>|required=1}} |
*{{ApiParam|token|2=<translate><!--T:10--> The token obtained in the previous request.</translate> <translate><!--T:28--> Take care to encode the <tvar name=1><code>+</code></tvar> as <tvar name=2><code>%2B</code></tvar></translate>|required=1}} |
||
*{{ApiParam|ccme|2=<translate><!--T:11--> If set, a copy of the email will be sent to you</translate>}} |
*{{ApiParam|ccme|2=<translate><!--T:11--> If set, a copy of the email will be sent to you</translate>}} |
||
Line 49: | Line 49: | ||
=== Examples === <!--T:12--> |
=== Examples === <!--T:12--> |
||
</translate> |
</translate> |
||
{{note|1=<translate><!--T:13--> 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.</translate>}} |
{{note|1=<translate><!--T:13--> In this example, all parameters are passed in a GET request just for the sake of simplicity. However, <tvar name=1>action=emailuser</tvar> requires POST requests; GET requests will cause an error.</translate>}} |
||
{{ApiEx |
{{ApiEx |
||
Line 68: | Line 68: | ||
<!-- Transclude Sample code --> |
<!-- Transclude Sample code --> |
||
<div style="overflow-y:hidden"> |
|||
{{:{{translatable}}/Sample code 1}} |
{{:{{translatable}}/Sample code 1}} |
||
</div> |
|||
<translate> |
<translate> |
||
=== Possible errors === <!--T:16--> |
=== Possible errors === <!--T:16--> |
||
Line 86: | Line 89: | ||
| notarget || {{int|apierror-notarget}} |
| notarget || {{int|apierror-notarget}} |
||
|- |
|- |
||
| noemail |
| noemail|| {{int|noemailtext}} |
||
|- |
|||
| nowikiemail|| {{int|nowikiemailtext}} |
|||
|} |
|} |
||
<translate> |
<translate> |
||
== Checking emailable status == <!--T:21--> |
== Checking emailable status == <!--T:21--> |
Latest revision as of 14:45, 26 April 2024
This page is part of the MediaWiki Action API documentation. |
Emailuser | ||
---|---|---|
Email a user. This module cannot be used as a generator. | ||
Prefix | none | |
Required rights | sendemail | |
Post only? | Yes | |
Generated help | Current | |
Version added |
|
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=query&meta=tokens , or by using the following method:
Result |
---|
{
"batchcomplete": "",
"query": {
"tokens": {
"csrftoken": "7773cbfff263682c97ffc74b8672cbf25a5e0045+\\"
}
}
}
|
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]Result |
---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<emailuser result="Success" />
</api>
|
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 | ⧼apierror-notarget⧽ |
noemail | This user has not specified a valid email address. |
nowikiemail | This user 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: |
action=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.
- 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.
- Send an email to the user WikiSysop with the text Content.
- api.php?action=emailuser&target=WikiSysop&text=Content&token=123ABC [open in sandbox]