Guía de inicio rápido
Crea una clave de API de prueba y usa un destinatario del simulador. Los mensajes de prueba utilizan la API y registran un resultado simulado sin entregar ningún correo.
El simulador no está disponible en este momento.
-
Configura tu espacio de trabajo
Crea tu cuenta, confirma tu dirección de correo electrónico e inicia sesión.
-
Crea una clave de API
Selecciona el modo de prueba al crear la clave. Las claves de prueba empiezan por mg_test_.
Crea una clave en tu espacio de trabajo y guarda el secreto en el entorno del servidor. Mantenlo fuera del código que se ejecuta en el navegador, de los repositorios y de los registros.
-
Envía un correo simulado
Define MAILGATE_API_KEY en el entorno de tu terminal y ejecuta esta solicitud. El simulador usa el remitente de ejemplo que aparece aquí.
Guarda MAILGATE_API_KEY en el entorno de tu terminal o en el gestor de secretos de tu servidor.
cURL
POST /api/v1/emailscurl --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/emailsconst 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/emailsimport 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)Una respuesta 202 incluye el ID del mensaje. La actividad del entorno de pruebas en tu panel muestra el resultado simulado. Para un mensaje distinto, elige un nuevo valor para Idempotency-Key.
-
Verifica un dominio de envío
Cuando el servicio esté habilitado, usa un dominio de envío verificado y una clave de API de producción para realizar envíos reales.
Añade un dominio a tu espacio de trabajo. Publica los registros DNS que aparecen en la configuración y espera a que finalice la verificación.
Destinatarios del simulador
| Destinatario | Resultado |
|---|---|
delivered@simulator.mailgate.test |
Entrega simulada |
bounced@simulator.mailgate.test |
Rebote simulado |
complained@simulator.mailgate.test |
Queja simulada |