ReadMail(Admin, Rank, Coupon)
public BackndReturnObject ReadMail(MailType mailType, string postIndate);
The inDate needed for claiming mail can be loaded with the mail loading method(Mail.GetMailList).
The mail may not be claimed even with a correct inDate if the mail is not loaded.
Only mail added to the mail list through the mail list loading can be claimed.
Parameters
Value | Type | Description |
---|---|---|
mailType | MailType | Type of the single mail to claim |
postIndate | string | inDate of the mail from which items were received |
MailType
Value | Description |
---|---|
Admin | Admin mail sent from BACKND Console |
Rank | Ranking mail sent automatically after ranking settlement |
Coupon | Coupon mail sent after using a coupon with the page created in Web Coupon Settings in BACKND Console |
User | User mail sent using each user's data |
Description
Claims one piece of mail using its indate.
You may use the same logic for claiming admin, ranking, and coupon mail, as they all have the same return values when claimed.
Different return values are provided for user mail.
- The data types "S", "L", and "M" in the return values of the previous mail function(Backnd.Player.Post) was removed.
- Even if indate exists, you cannot claim the mail if it is a different MailType.
- The mail is removed from the list after being claimed. You can check which items are claimed using returnValue.
- Users who have claimed the mail are displayed in the mail details in the console's Mail Management along with the date received.(not the case for coupon and user mail)
- You cannot claim expired mail.
- Information of the received item will not be inserted/modified in the user's DB automatically, so you must update it manually to the recipient's game information in the client.
Example
Synchronous
MailType type = MailType.Admin;
//Load mail list
BackndReturnObject bro = Backnd.Mail.GetMailList(type, limit);
BACKND.LitJson.JsonData json = bro.GetReturnValuetoJSON()["postItems"];
//Get the inDate of the 0th mail in the mail list
string recentPostIndate = json[0]["inDate"].ToString();
// Claim mail with the same MailType
Backnd.Mail.ReadMail(type, recentPostIndate);
Asynchronous
//Mail type
MailType type = MailType.Admin;
//Load mail list
Backnd.Mail.GetMailList(type, limit, callback => {
BACKND.LitJson.JsonData json = callback.GetReturnValuetoJSON()["postItems"];
//Get the inDate of the 0th mail in the mail list
string recentPostIndate = json[0]["inDate"].ToString();
// Claim mail
Backnd.Mail.ReadMail(type, recentPostIndate, callback2 => {
if(callback2.IsSuccess()) {
Debug.Log("Successfully claimed the mail.");
}
});
});
Return cases
Success cases
When the mail is claimed successfully
statusCode : 200
returnValue : refer to GetReturnValuetoJSON
Error cases
When a non-existent postIndate is entered
statusCode : 404
errorCode : NotFoundException
GetReturnValuetoJSON
Mail with 0 types of item
{
"postItems": []
}
Mail with 1 type of item
Ranking mails can only have 1 item registered, so only the following format is returned.
{
"postItems": [
{
"item": {
"chartFileName": "chartExample.xlsx",
"itemID": "i101",
"itemName": "Item111",
"hpPower": "1",
"aabab": "1"
},
"itemCount": 1,
"chartName": "DataTable"
}
]
}
Mail with 2 or more types of item
{
"postItems": [
{
"item": {
"chartFileName": "chartExample.xlsx",
"itemID": "i101",
"itemName": "Item111",
"hpPower": "1",
"aabab": "1"
},
"itemCount": 1,
"chartName": "DataTable"
},
{
"item": {
"chartFileName": "Weapon.xlsx",
"itemID": "sword1",
"itemName": "Longsword",
"atk": "17",
"money": "350"
},
"itemCount": 2
"chartName": "DataTable"
}
]
}
Sample code
public class ReceiveItem {
public string chartFileName;
public string itemID;
public string itemName;
public int hpPower;
public int itemCount;
public override string ToString() {
return $"chartFileName:{chartFileName}\n" +
$"itemID:{itemID}\n" +
$"itemName:{itemName}\n" +
$"hpPower:{hpPower}\n" +
$"itemCount:{itemCount}\n";
}
}
public void ReadMailTest() {
BackndReturnObject bro = Backnd.Mail.GetMailList(MailType.Coupon, 100);
if(bro.IsSuccess()) {
string postIndate = bro.GetReturnValuetoJSON()["postList"][0]["inDate"].ToString();
var receiveBro = Backnd.Mail.ReadMail(MailType.Coupon, postIndate);
if(receiveBro.IsSuccess() == false) {
Debug.LogError("An error occurred while claiming mail. : " + receiveBro);
return;
}
BACKND.LitJson.JsonData receivePostItemJson = receiveBro.GetReturnValuetoJSON()["postItems"];
for(int i = 0; i < receivePostItemJson.Count; i++) {
ReceiveItem item = new ReceiveItem();
if(receivePostItemJson[i]["item"].ContainsKey("itemName")) {
item.itemName = receivePostItemJson[i]["item"]["itemName"].ToString();
}
// chartFileName does not exist for ranking rewards.
if(receivePostItemJson[i]["item"].ContainsKey("chartFileName")) {
item.chartFileName = receivePostItemJson[i]["item"]["chartFileName"].ToString();
}
if(receivePostItemJson[i]["item"].ContainsKey("itemID")) {
item.itemID = receivePostItemJson[i]["item"]["itemID"].ToString();
}
if(receivePostItemJson[i]["item"].ContainsKey("hpPower")) {
item.hpPower = int.Parse(receivePostItemJson[i]["item"]["hpPower"].ToString());
}
item.itemCount = int.Parse(receivePostItemJson[i]["itemCount"].ToString());
Debug.Log(item.ToString());
}
}
}