අන්තර්ගතය වෙත යන්න
MailGateAPI

ඉක්මන් ආරම්භය

පරීක්ෂණ API යතුරක් සාදා අනුකරණ ලබන්නෙකුගේ ලිපිනයක් භාවිත කරන්න. පරීක්ෂණ පණිවිඩ API එක ක්‍රියාත්මක කර අනුකරණ ප්‍රතිඵල සටහන් කරයි. ඒවා සැබැවින්ම බෙදාහරින්නේ නැත.

අනුකරණ පද්ධතිය දැනට ලබා ගත නොහැක.

  1. ඔබේ වැඩබිම සකසන්න

    ගිණුමක් සාදා, ඊමේල් ලිපිනය තහවුරු කර, පිවිසෙන්න.

  2. API යතුරක් සාදන්න

    යතුර සාදන විට පරීක්ෂණ ප්‍රකාරය තෝරන්න. පරීක්ෂණ යතුරු mg_test_ යන්නෙන් ආරම්භ වේ.

    වැඩබිමේ යතුරක් සාදා එහි රහස් අගය ඔබේ සේවාදායක පරිසරයේ ගබඩා කරන්න. එය බ්‍රවුසර කේතයට, කේත ගබඩාවලට හෝ ලොග් සටහන්වලට එක් කිරීමෙන් වළකින්න.

  3. අනුකරණ ඊමේලයක් යවන්න

    ඔබේ shell පරිසරයේ MAILGATE_API_KEY සකසා මෙම ඉල්ලීම ක්‍රියාත්මක කරන්න. අනුකරණ පද්ධතිය මෙහි පෙන්වන උදාහරණ යවන්නා භාවිත කරයි.

    MAILGATE_API_KEY ඔබේ ටර්මිනලයේ හෝ පසුඅන්තයේ රහස් කළමනාකරණ මෙවලමේ තබන්න.

    cURL

    POST /api/v1/emails
    curl --fail-with-body --request POST https://mailgateapi.com/api/v1/emails \
      --header "Authorization: Bearer ${MAILGATE_API_KEY:?Set MAILGATE_API_KEY}" \
      --header "Content-Type: application/json" \
      --header "Idempotency-Key: first-test-1" \
      --data '{
        "from": "noreply@simulator.mailgate.test",
        "to": "delivered@simulator.mailgate.test",
        "subject": "My first test",
        "text": "Hello from the MailGateAPI simulator."
      }'

    PHP

    POST /api/v1/emails
    <?php
    
    $key = getenv('MAILGATE_API_KEY') ?: throw new RuntimeException('Set MAILGATE_API_KEY');
    $request = curl_init('https://mailgateapi.com/api/v1/emails');
    curl_setopt_array($request, [
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 20,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer '.$key,
            'Content-Type: application/json',
            'Idempotency-Key: first-test-1',
        ],
        CURLOPT_POSTFIELDS => json_encode([
            'from' => 'noreply@simulator.mailgate.test',
            'to' => 'delivered@simulator.mailgate.test',
            'subject' => 'My first test',
            'text' => 'Hello from the MailGateAPI simulator.',
        ], JSON_THROW_ON_ERROR),
    ]);
    
    $body = curl_exec($request);
    if ($body === false) {
        throw new RuntimeException(curl_error($request));
    }
    echo $body, PHP_EOL;
    exit(curl_getinfo($request, CURLINFO_RESPONSE_CODE) === 202 ? 0 : 1);

    Node.js

    POST /api/v1/emails
    const key = process.env.MAILGATE_API_KEY;
    if (!key) throw new Error('Set MAILGATE_API_KEY');
    
    fetch('https://mailgateapi.com/api/v1/emails', {
      method: 'POST',
      signal: AbortSignal.timeout(20_000),
      headers: {
        Authorization: `Bearer ${key}`,
        'Content-Type': 'application/json',
        'Idempotency-Key': 'first-test-1',
      },
      body: JSON.stringify({
        from: 'noreply@simulator.mailgate.test',
        to: 'delivered@simulator.mailgate.test',
        subject: 'My first test',
        text: 'Hello from the MailGateAPI simulator.',
      }),
    }).then(async (response) => {
      console.log(await response.text());
      if (response.status !== 202) process.exitCode = 1;
    }).catch((error) => {
      console.error(error.message);
      process.exitCode = 1;
    });

    Python

    POST /api/v1/emails
    import json
    import os
    from urllib.error import HTTPError
    from urllib.request import Request, urlopen
    
    request = Request(
        "https://mailgateapi.com/api/v1/emails",
        method="POST",
        headers={
            "Authorization": "Bearer " + os.environ["MAILGATE_API_KEY"],
            "Content-Type": "application/json",
            "Idempotency-Key": "first-test-1",
        },
        data=json.dumps({
            "from": "noreply@simulator.mailgate.test",
            "to": "delivered@simulator.mailgate.test",
            "subject": "My first test",
            "text": "Hello from the MailGateAPI simulator.",
        }).encode("utf-8"),
    )
    
    try:
        with urlopen(request, timeout=20) as response:
            print(response.read().decode("utf-8"))
    except HTTPError as error:
        print(error.read().decode("utf-8"))
        raise SystemExit(1)

    202 ප්‍රතිචාරයට පණිවිඩ හැඳුනුම ඇතුළත් වේ. පාලක පුවරුවේ පරීක්ෂණ ක්‍රියාකාරකම් යටතේ අනුකරණ ප්‍රතිඵලය පෙන්වයි. වෙනත් පණිවිඩයක් සඳහා නව Idempotency-Key අගයක් තෝරන්න.

  4. යැවීමේ වසමක් සත්‍යාපනය කරන්න

    සේවාව සක්‍රිය කළ පසු සැබෑ ඊමේල් යැවීමට සත්‍යාපිත යැවීමේ වසමක් සහ සජීවී API යතුරක් භාවිත කරන්න.

    වැඩබිමට වසමක් එක් කරන්න. සැකසුමේ දක්වන DNS වාර්තා ප්‍රකාශයට පත් කර සත්‍යාපනය අවසන් වන තෙක් රැඳී සිටින්න.

අනුකරණය සඳහා ලබන්නන්ගේ ලිපින

ලබන්නා ප්‍රතිඵලය
delivered@simulator.mailgate.test අනුකරණ බෙදාහැරීම
bounced@simulator.mailgate.test අනුකරණ ආපසු හැරවීම
complained@simulator.mailgate.test අනුකරණ පැමිණිල්ල
API යොමුව