Mailo API Kullanım Kılavuzu
Mailo API ile mail, SMS ve WhatsApp gönderimini entegre edin. RESTful API tasarımı, kolay kullanım ve güvenilir altyapı.
Giriş
Mailo API, uygulamalarınızdan kolayca mail ve SMS göndermenizi sağlayan RESTful bir API'dir. JSON formatında veri alışverişi yapar ve HTTPS üzerinden güvenli iletişim sağlar.
Özellikler
- Mail Gönderimi: HTML ve düz metin desteği ile mail gönderimi
- SMS Gönderimi: NetGSM entegrasyonu ile SMS gönderimi
- WhatsApp Gönderimi: QR ile bağlanan hesaplar üzerinden WhatsApp mesajı gönderimi
- Birden Fazla SMTP/WhatsApp Hesabı: Farklı SMTP sunucuları ve WhatsApp hesaplarıyla gönderim
- API Key Yönetimi: Her proje için ayrı API key'ler, kanal bazlı yetkilendirme
- Günlük Limitler: API key bazında günlük gönderim limiti
- Detaylı Loglama: Tüm gönderimlerin detaylı logları
- Türkçe Karakter Desteği: Full UTF-8 ve Türkçe karakter desteği
Kimlik Doğrulama
Mailo API, API Key tabanlı kimlik doğrulama kullanır. API Key'inizi HTTP header'ında göndermelisiniz.
API Key Alma
- Mailo admin paneline giriş yapın
- API Keys menüsüne gidin
- "Yeni API Key" butonuna tıklayın
- Gerekli bilgileri doldurup API Key'inizi oluşturun
- Oluşturulan API Key'i güvenli bir yere kaydedin (bir daha göremezsiniz!)
API Key Kullanımı
API Key'inizi üç farklı yöntemle gönderebilirsiniz:
1. HTTP Header (Önerilen)
X-API-Key: your_api_key_here
2. Query String
?api_key=your_api_key_here
3. POST Data
{"api_key": "your_api_key_here"}
Base URL
Tüm API istekleri aşağıdaki base URL üzerinden yapılır:
http://mailo.mekanode.com//api/
API Endpoints
| Endpoint | Metod | Açıklama |
|---|---|---|
/api/send-mail.php |
POST | Mail gönderimi |
/api/send-sms.php |
POST | SMS gönderimi |
/api/send-whatsapp.php |
POST | WhatsApp mesajı gönderimi |
Rate Limiting (Hız Sınırları)
Her API Key için günlük gönderim limiti vardır. Bu limit API Key oluşturulurken belirlenir ve her gece saat 00:00'da sıfırlanır.
remaining_quota alanında kalan gönderim hakkınızı görebilirsiniz.
Limit Aşımı
Günlük limitiniz dolduğunda 401 Unauthorized hatası alırsınız:
{
"success": false,
"error": "Geçersiz API key veya günlük limit aşıldı"
}
Mail Gönderme
Mail göndermek için aşağıdaki endpoint'i kullanın:
/api/send-mail.php
Request Headers
| Header | Değer | Açıklama |
|---|---|---|
Content-Type |
application/json |
Zorunlu |
X-API-Key |
your_api_key |
Zorunlu |
Request Body Parametreleri
| Parametre | Tip | Zorunluluk | Açıklama |
|---|---|---|---|
to |
string | Zorunlu | Alıcı email adresi (örn: user@example.com) |
subject |
string | Zorunlu | Mail konusu |
body |
string | Zorunlu | Mail içeriği (HTML veya düz metin) |
is_html |
boolean | Opsiyonel | HTML mail mi? (varsayılan: true) |
from_email |
string | Opsiyonel | Gönderici email (SMTP ayarlarından gelir) |
from_name |
string | Opsiyonel | Gönderici adı |
Başarılı Yanıt
{
"success": true,
"message": "Mail başarıyla gönderildi",
"remaining_quota": 999
}
Hata Yanıtları
{
"success": false,
"error": "'to' alanı gereklidir (telefon numarası)"
}
{
"success": false,
"error": "Geçersiz API key veya günlük limit aşıldı"
}
{
"success": false,
"error": "Mail gönderilemedi. Lütfen daha sonra tekrar deneyin."
}
Mail Gönderme Örnekleri
cURL
curl -X POST http://mailo.mekanode.com//api/send-mail.php \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "recipient@example.com",
"subject": "Hoş Geldiniz!",
"body": "Merhaba!
Hoş geldiniz mesajı.
",
"is_html": true
}'
PHP
<?php
$apiKey = 'YOUR_API_KEY';
$apiUrl = 'http://mailo.mekanode.com//api/send-mail.php';
$data = [
'to' => 'recipient@example.com',
'subject' => 'Hoş Geldiniz!',
'body' => '<h1>Merhaba!</h1><p>Hoş geldiniz mesajı.</p>',
'is_html' => true,
'from_name' => 'Firma Adı'
];
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
if ($httpCode === 200 && $result['success']) {
echo "Mail gönderildi! Kalan kota: " . $result['remaining_quota'];
} else {
echo "Hata: " . $result['error'];
}
?>
JavaScript (Node.js)
const axios = require('axios');
const apiKey = 'YOUR_API_KEY';
const apiUrl = 'http://mailo.mekanode.com//api/send-mail.php';
const data = {
to: 'recipient@example.com',
subject: 'Hoş Geldiniz!',
body: 'Merhaba!
Hoş geldiniz mesajı.
',
is_html: true,
from_name: 'Firma Adı'
};
axios.post(apiUrl, data, {
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
}
})
.then(response => {
console.log('Mail gönderildi!');
console.log('Kalan kota:', response.data.remaining_quota);
})
.catch(error => {
console.error('Hata:', error.response.data.error);
});
Python
import requests
import json
api_key = 'YOUR_API_KEY'
api_url = 'http://mailo.mekanode.com//api/send-mail.php'
data = {
'to': 'recipient@example.com',
'subject': 'Hoş Geldiniz!',
'body': 'Merhaba!
Hoş geldiniz mesajı.
',
'is_html': True,
'from_name': 'Firma Adı'
}
headers = {
'X-API-Key': api_key,
'Content-Type': 'application/json'
}
response = requests.post(api_url, json=data, headers=headers)
result = response.json()
if response.status_code == 200 and result['success']:
print(f"Mail gönderildi! Kalan kota: {result['remaining_quota']}")
else:
print(f"Hata: {result['error']}")
SMS Gönderme
SMS göndermek için aşağıdaki endpoint'i kullanın:
/api/send-sms.php
Request Headers
| Header | Değer | Açıklama |
|---|---|---|
Content-Type |
application/json |
Zorunlu |
X-API-Key |
your_api_key |
Zorunlu |
Request Body Parametreleri
| Parametre | Tip | Zorunluluk | Açıklama |
|---|---|---|---|
to |
string | Zorunlu | Alıcı telefon numarası (örn: 905xxxxxxxxx veya 0532xxxxxxx) |
message |
string | Zorunlu | SMS mesajı içeriği |
subject |
string | Opsiyonel | SMS konusu (mesajın başına eklenir) |
Başarılı Yanıt
{
"success": true,
"message": "SMS başarıyla gönderildi",
"remaining_quota": 999
}
Hata Yanıtları
{
"success": false,
"error": "'to' alanı gereklidir (telefon numarası)"
}
{
"success": false,
"error": "Bu API key SMS gönderimi için yetkilendirilmemiş"
}
SMS Gönderme Örnekleri
cURL
curl -X POST http://mailo.mekanode.com//api/send-sms.php \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "905xxxxxxxxx",
"message": "Doğrulama kodunuz: 123456",
"subject": "Güvenlik Kodu"
}'
PHP
<?php
$apiKey = 'YOUR_API_KEY';
$apiUrl = 'http://mailo.mekanode.com//api/send-sms.php';
$data = [
'to' => '905xxxxxxxxx',
'message' => 'Doğrulama kodunuz: 123456',
'subject' => 'Güvenlik Kodu'
];
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
if ($httpCode === 200 && $result['success']) {
echo "SMS gönderildi! Kalan kota: " . $result['remaining_quota'];
} else {
echo "Hata: " . $result['error'];
}
?>
JavaScript (Node.js)
const axios = require('axios');
const apiKey = 'YOUR_API_KEY';
const apiUrl = 'http://mailo.mekanode.com//api/send-sms.php';
const data = {
to: '905xxxxxxxxx',
message: 'Doğrulama kodunuz: 123456',
subject: 'Güvenlik Kodu'
};
axios.post(apiUrl, data, {
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
}
})
.then(response => {
console.log('SMS gönderildi!');
console.log('Kalan kota:', response.data.remaining_quota);
})
.catch(error => {
console.error('Hata:', error.response.data.error);
});
Python
import requests
api_key = 'YOUR_API_KEY'
api_url = 'http://mailo.mekanode.com//api/send-sms.php'
data = {
'to': '905xxxxxxxxx',
'message': 'Doğrulama kodunuz: 123456',
'subject': 'Güvenlik Kodu'
}
headers = {
'X-API-Key': api_key,
'Content-Type': 'application/json'
}
response = requests.post(api_url, json=data, headers=headers)
result = response.json()
if response.status_code == 200 and result['success']:
print(f"SMS gönderildi! Kalan kota: {result['remaining_quota']}")
else:
print(f"Hata: {result['error']}")
WhatsApp Gönderme
WhatsApp mesajı göndermek için aşağıdaki endpoint'i kullanın:
/api/send-whatsapp.php
Request Headers
| Header | Değer | Açıklama |
|---|---|---|
Content-Type |
application/json |
Zorunlu |
X-API-Key |
your_api_key |
Zorunlu |
Request Body Parametreleri
| Parametre | Tip | Zorunluluk | Açıklama |
|---|---|---|---|
to |
string | Zorunlu | Alıcı telefon numarası (örn: 905xxxxxxxxx veya 0532xxxxxxx) |
message |
string | Zorunlu | WhatsApp mesajı içeriği |
Başarılı Yanıt
{
"success": true,
"message": "WhatsApp mesajı başarıyla gönderildi",
"remaining_quota": 999
}
Hata Yanıtları
{
"success": false,
"error": "'to' alanı gereklidir (telefon numarası)"
}
{
"success": false,
"error": "Bu API key WhatsApp gönderimi için yetkilendirilmemiş"
}
{
"success": false,
"error": "WhatsApp mesajı gönderilemedi. Lütfen logları kontrol edin."
}
WhatsApp Gönderme Örnekleri
cURL
curl -X POST http://mailo.mekanode.com//api/send-whatsapp.php \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "905xxxxxxxxx",
"message": "Merhaba, siparişiniz kargoya verildi!"
}'
PHP
<?php
$apiKey = 'YOUR_API_KEY';
$apiUrl = 'http://mailo.mekanode.com//api/send-whatsapp.php';
$data = [
'to' => '905xxxxxxxxx',
'message' => 'Merhaba, siparişiniz kargoya verildi!'
];
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
if ($httpCode === 200 && $result['success']) {
echo "WhatsApp mesajı gönderildi! Kalan kota: " . $result['remaining_quota'];
} else {
echo "Hata: " . $result['error'];
}
?>
JavaScript (Node.js)
const axios = require('axios');
const apiKey = 'YOUR_API_KEY';
const apiUrl = 'http://mailo.mekanode.com//api/send-whatsapp.php';
const data = {
to: '905xxxxxxxxx',
message: 'Merhaba, siparişiniz kargoya verildi!'
};
axios.post(apiUrl, data, {
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
}
})
.then(response => {
console.log('WhatsApp mesajı gönderildi!');
console.log('Kalan kota:', response.data.remaining_quota);
})
.catch(error => {
console.error('Hata:', error.response.data.error);
});
Python
import requests
api_key = 'YOUR_API_KEY'
api_url = 'http://mailo.mekanode.com//api/send-whatsapp.php'
data = {
'to': '905xxxxxxxxx',
'message': 'Merhaba, siparişiniz kargoya verildi!'
}
headers = {
'X-API-Key': api_key,
'Content-Type': 'application/json'
}
response = requests.post(api_url, json=data, headers=headers)
result = response.json()
if response.status_code == 200 and result['success']:
print(f"WhatsApp mesajı gönderildi! Kalan kota: {result['remaining_quota']}")
else:
print(f"Hata: {result['error']}")
Hata Kodları
Mailo API standart HTTP durum kodlarını kullanır:
| Kod | Açıklama | Çözüm |
|---|---|---|
| 200 | Başarılı | İstek başarıyla işlendi |
| 400 | Bad Request | Gerekli parametreler eksik veya hatalı. Hata mesajını kontrol edin. |
| 401 | Unauthorized | API key geçersiz veya günlük limit aşıldı. API key'inizi kontrol edin. |
| 403 | Forbidden | API key'iniz bu servise yetkili değil. Servis tipini kontrol edin. |
| 405 | Method Not Allowed | Sadece POST metodu desteklenir. GET yerine POST kullanın. |
| 500 | Internal Server Error | Sunucu hatası. Lütfen daha sonra tekrar deneyin veya destek ile iletişime geçin. |
En İyi Uygulamalar
1. API Key Güvenliği
- API key'lerinizi asla public repository'lerde paylaşmayın
- Environment variable veya güvenli config dosyalarında saklayın
- Her proje için ayrı API key kullanın
- Kullanılmayan API key'leri devre dışı bırakın
2. Hata Yönetimi
- Her API isteğinden sonra HTTP durum kodunu kontrol edin
- Hata durumlarında yanıttaki
errormesajını logla - Rate limit hatalarında exponential backoff kullanın
- Timeout sürelerini uygun şekilde ayarlayın (önerilen: 30 saniye)
3. Mail Gönderimi
- HTML mail gönderirken her zaman düz metin alternatifi ekleyin
- Mail içeriğinde XSS saldırılarına karşı input'ları sanitize edin
- Büyük toplu mail gönderimlerde batch processing kullanın
- Unsubscribe (abonelik iptali) linkleri ekleyin
4. SMS Gönderimi
- Telefon numaralarını göndermeden önce doğrulayın
- Türkçe karakter kullanıyorsanız 70 karakter limitini unutmayın
- Önemli bildirimler için SMS, pazarlama için mail tercih edin
- SMS içeriğinde URL kullanıyorsanız kısa URL servisleri kullanın
5. WhatsApp Gönderimi
- WhatsApp'ı garantili değil, "en iyi çaba" (best-effort) bir kanal olarak tasarlayın; kritik bildirimler için mail/SMS'e de yedeklilik sağlayın
- Yüksek hacimli/tekrarlı gönderimlerden kaçının, numaranın askıya alınma riskini artırır
- Admin panelden bağlantı durumunu ("Bağlı" / "Bağlantı Koptu" / "Oturum Kapandı") düzenli kontrol edin
- Gönderim başarısız olursa kullanıcıyı başka bir kanaldan (mail/SMS) bilgilendirmeyi planlayın
6. Performans
- Toplu gönderimler için asenkron işleme kullanın
- Başarılı isteklerin yanıtlarını cache'leyin
- Connection pooling kullanın
- Gzip compression kullanın
7. Monitoring ve Logging
- Tüm API isteklerini loglayın
- Kalan kotanızı düzenli kontrol edin
- Başarı oranlarını takip edin
- Hata oranları yükseldiğinde alarm kurun
Örnek: Retry Logic (PHP)
<?php
function sendMailWithRetry($apiKey, $data, $maxRetries = 3) {
$apiUrl = 'https://example.com/api/send-mail.php';
$attempt = 0;
while ($attempt < $maxRetries) {
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Başarılı
if ($httpCode === 200) {
return json_decode($response, true);
}
// 4xx hataları için retry yapma
if ($httpCode >= 400 && $httpCode < 500) {
return json_decode($response, true);
}
// 5xx hataları için retry yap
$attempt++;
if ($attempt < $maxRetries) {
// Exponential backoff: 1s, 2s, 4s
sleep(pow(2, $attempt - 1));
}
}
return ['success' => false, 'error' => 'Max retry limit reached'];
}
?>
Webhooks (Yakında)
Webhook özelliği yakında eklenecektir. Webhook'lar ile mail ve SMS gönderim durumları hakkında gerçek zamanlı bildirim alabileceksiniz.
Planlanan Özellikler
- Mail gönderim başarı/hata bildirimleri
- SMS gönderim başarı/hata bildirimleri
- Mail açılma takibi (open tracking)
- Link tıklama takibi (click tracking)
- Bounce ve spam bildirimleri
Destek
API kullanımı ile ilgili sorularınız için:
- Dokümantasyon: Bu sayfayı yer imlerinize ekleyin
- Admin Panel: Mailo Admin Panel
- GitHub: Örnek kodlar ve entegrasyonlar için (yakında)