انتقل للمحتوى
Rasel Mailمركز المساعدة
الأقسام والأدلة
للمطورين

إرسال أول رسالة من موقعك

جهّز الدومين والمشروع، ثم جرّب cURL وJavaScript وPython وPHP.

آخر تحديث تحريري: ٣٠ أكتوبر ٢٠٢٦
في هذا الدليل

جهّز مشروع الإرسال

  1. فعّل الاشتراك المدفوع وأضف دومينًا خاصًا وأكمل سجلات إرساله.
  2. افتح لوحة التحكم ← التطبيقات ← إرسال رسائل المواقع. اطلب حصة إرسال وتابع تأكيد الدفع يدويًا.
  3. أنشئ مشروعًا واختار الدومين المطلوب. انسخ المفتاح الذي يظهر مرة واحدة واحفظه في مخزن أسرار الخادم.
  4. استبدل عناوين المثال بعناوين فعلية تخص اختبارك. يجب أن ينتمي from إلى دومين المشروع.

تجربة cURL

إرسال رسالة اختبار
curl -i 'https://raselmail.com/api/v1/delivery/messages'   -H "Authorization: Bearer $RASEL_API_KEY"   -H 'Idempotency-Key: order-123-confirmation'   -H 'Content-Type: application/json'   --data '{"from":"no-reply@example.com","to":["customer@example.net"],"subject":"Order received","text":"We received your order.","html":"<p>We received your order.</p>"}'

أمثلة على خادم التطبيق

JavaScript / Node.js
const key = process.env.RASEL_API_KEY;
if (!key) throw new Error('Missing RASEL_API_KEY');
const response = await fetch('https://raselmail.com/api/v1/delivery/messages', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer ' + key,
    'Content-Type': 'application/json',
    'Idempotency-Key': 'order-123-confirmation',
  },
  body: JSON.stringify({"from":"no-reply@example.com","to":["customer@example.net"],"subject":"Order received","text":"We received your order.","html":"<p>We received your order.</p>"}),
});
const result = await response.json();
if (!response.ok) throw new Error(result.error || 'Send request failed');
console.log(result.id, result.state);
Python — بدون مكتبات إضافية
import json, os, urllib.request, urllib.error

payload = {"from":"no-reply@example.com","to":["customer@example.net"],"subject":"Order received","text":"We received your order.","html":"<p>We received your order.</p>"}
request = urllib.request.Request(
    'https://raselmail.com/api/v1/delivery/messages',
    data=json.dumps(payload).encode('utf-8'),
    headers={
        'Authorization': 'Bearer ' + os.environ['RASEL_API_KEY'],
        'Content-Type': 'application/json',
        'Idempotency-Key': 'order-123-confirmation',
    }, method='POST')
try:
    with urllib.request.urlopen(request, timeout=20) as response:
        result = json.load(response)
        print(result['id'], result['state'])
except urllib.error.HTTPError as error:
    print(error.code, error.read().decode('utf-8'))
    raise
PHP — باستخدام cURL
<?php
$key = getenv('RASEL_API_KEY');
if (!$key) { throw new RuntimeException('Missing RASEL_API_KEY'); }
$request = curl_init('https://raselmail.com/api/v1/delivery/messages');
curl_setopt_array($request, [
  CURLOPT_POST => true,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 20,
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer ' . $key,
    'Content-Type: application/json',
    'Idempotency-Key: order-123-confirmation',
  ],
  CURLOPT_POSTFIELDS => '{"from":"no-reply@example.com","to":["customer@example.net"],"subject":"Order received","text":"We received your order.","html":"<p>We received your order.</p>"}',
]);
$body = curl_exec($request);
if ($body === false) { throw new RuntimeException(curl_error($request)); }
$status = curl_getinfo($request, CURLINFO_RESPONSE_CODE);
curl_close($request);
$result = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
if ($status < 200 || $status >= 300) {
  throw new RuntimeException($result['error'] ?? 'Send request failed');
}
echo $result['id'];

ماذا بعد الرد؟

مثال رد HTTP 202
{"id":"11111111-1111-4111-8111-111111111111","state":"queued","recipient_count":1}

احفظ المعرّف واربطه بالطلب عندك، ثم تابع الحالة. queued تعني أن الطلب اتسجل، وaccepted تعني قبول مزود الإرسال، وليس وصولًا مؤكدًا للوارد. لا تطبع المفاتيح أو روابط الاستعادة في السجلات.