Mailgun कनेक्टर
अपने ट्रांज़ैक्शनल और मार्केटिंग ईमेल डेटा को एकीकृत करने, डिलीवरी इवेंट्स और एंगेजमेंट मेट्रिक्स सिंक करने, और अपने ईमेल इन्फ्रास्ट्रक्चर को एक एकल ग्राहक दृश्य में समेकित करने के लिए Tajo के माध्यम से Mailgun को Brevo से कनेक्ट करें।
अवलोकन
| गुण | मान |
|---|---|
| प्लेटफ़ॉर्म | Mailgun (by Sinch) |
| श्रेणी | Email Marketing |
| सेटअप जटिलता | आसान |
| आधिकारिक इंटीग्रेशन | नहीं |
| सिंक किया गया डेटा | इवेंट्स, कॉन्टैक्ट्स, Deliverability, कैंपेन |
| Auth Method | API Key (HTTP Basic Auth) |
विशेषताएं
- Delivery इवेंट सिंक - delivered, bounced, opened, और clicked इवेंट्स ट्रैक करें
- एंगेजमेंट मेट्रिक्स - open और click rates को Brevo कॉन्टैक्ट एट्रिब्यूट्स में सिंक करें
- Bounce प्रबंधन - Brevo में बाउंस्ड एड्रेस को स्वचालित रूप से suppress करें
- Complaint हैंडलिंग - list हाइजीन के लिए spam complaints सिंक करें
- Domain reputation - sending domain स्वास्थ्य और deliverability की निगरानी करें
- Transactional ईमेल ट्रैकिंग - transactional sends को मार्केटिंग डेटा के साथ correlate करें
पूर्वावश्यकताएं
शुरू करने से पहले, सुनिश्चित करें कि आपके पास है:
- एक सत्यापित sending domain के साथ एक Mailgun खाता
- Mailgun Dashboard से एक Mailgun API key
- API एक्सेस वाला एक Brevo खाता
- कनेक्टर अनुमतियों के साथ एक Tajo खाता
प्रमाणीकरण
API Key प्रमाणीकरण
Mailgun HTTP Basic Authentication का उपयोग करता है जिसमें username के रूप में api और password के रूप में आपकी API key होती है:
# Get your API key from https://app.mailgun.com/settings/api_securityexport MAILGUN_API_KEY=key-your-api-keyexport MAILGUN_DOMAIN=your-domain.comexport TAJO_API_KEY=your_tajo_api_keyexport BREVO_API_KEY=your_brevo_api_key// HTTP Basic Auth formatconst headers = { 'Authorization': `Basic ${Buffer.from( `api:${process.env.MAILGUN_API_KEY}` ).toString('base64')}`};
// Or using curl// curl -s --user 'api:YOUR_API_KEY' ...API Key प्रकार
Mailgun domain-specific sending keys और account-level API keys प्रदान करता है। message operations के लिए domain sending keys और management operations के लिए account API key का उपयोग करें।
कॉन्फ़िगरेशन
बुनियादी सेटअप
connectors: mailgun: enabled: true api_key: "${MAILGUN_API_KEY}" domain: "${MAILGUN_DOMAIN}" region: "us" # or "eu" for EU region
sync: events: true contacts: true bounces: true complaints: true schedule: "*/15 * * * *" # Every 15 minutes
webhook: signing_key: "${MAILGUN_WEBHOOK_SIGNING_KEY}"
lists: engaged: 30 bounced: 31 complained: 32फ़ील्ड मैपिंग
field_mapping: email: email first_name: FIRSTNAME last_name: LASTNAME open_rate: MG_OPEN_RATE click_rate: MG_CLICK_RATE last_delivered: MG_LAST_DELIVERED bounce_type: MG_BOUNCE_TYPE engagement_score: MG_ENGAGEMENT unsubscribed: MG_UNSUBSCRIBEDAPI एंडपॉइंट्स
| एंडपॉइंट | मेथड | विवरण |
|---|---|---|
https://api.mailgun.net/v3/{domain}/messages | POST | ईमेल messages भेजें |
https://api.mailgun.net/v3/{domain}/events | GET | इवेंट logs क्वेरी करें |
https://api.mailgun.net/v3/{domain}/bounces | GET | bounces सूचीबद्ध करें |
https://api.mailgun.net/v3/{domain}/complaints | GET | complaints सूचीबद्ध करें |
https://api.mailgun.net/v3/{domain}/unsubscribes | GET | unsubscribes सूचीबद्ध करें |
https://api.mailgun.net/v3/{domain}/tags | GET | tags सूचीबद्ध करें |
https://api.mailgun.net/v3/{domain}/tags/{tag}/stats | GET | tag आंकड़े प्राप्त करें |
https://api.mailgun.net/v3/lists | GET | mailing lists सूचीबद्ध करें |
https://api.mailgun.net/v3/domains | GET | domains सूचीबद्ध करें |
https://api.mailgun.net/v4/address/validate | POST | ईमेल पता मान्य करें |
EU Region
EU-आधारित Mailgun अकाउंट्स के लिए, सभी API एंडपॉइंट्स के लिए https://api.mailgun.net के बजाय https://api.eu.mailgun.net का उपयोग करें।
कोड उदाहरण
कनेक्टर प्रारंभ करें
import { TajoClient } from '@tajo/sdk';
const tajo = new TajoClient({ apiKey: process.env.TAJO_API_KEY, brevoApiKey: process.env.BREVO_API_KEY});
await tajo.connectors.connect('mailgun', { apiKey: process.env.MAILGUN_API_KEY, domain: process.env.MAILGUN_DOMAIN, region: 'us'});Mailgun API के माध्यम से एक संदेश भेजें
// Send an email using Mailgun's Messages APIconst formData = new URLSearchParams();formData.append('from', `Your App <noreply@${domain}>`);formData.append('subject', 'Welcome to our platform');formData.append('html', '<h1>Welcome!</h1><p>Thanks for signing up.</p>');formData.append('o:tag', 'welcome-email');formData.append('o:tracking', 'yes');
const response = await fetch( `https://api.mailgun.net/v3/${domain}/messages`, { method: 'POST', headers: { 'Authorization': `Basic ${Buffer.from(`api:${apiKey}`).toString('base64')}` }, body: formData });
const result = await response.json();// { id: '<[email protected]>', message: 'Queued. Thank you.' }Brevo में ईमेल इवेंट्स सिंक करें
// Query Mailgun events and sync engagement dataconst eventsResponse = await fetch( `https://api.mailgun.net/v3/${domain}/events?` + new URLSearchParams({ begin: lastSyncDate, ascending: 'yes', limit: 300, event: 'delivered OR opened OR clicked' }), { headers: { 'Authorization': `Basic ${Buffer.from(`api:${apiKey}`).toString('base64')}` } });
const { items, paging } = await eventsResponse.json();
for (const event of items) { const email = event.recipient;
switch (event.event) { case 'delivered': await tajo.contacts.update(email, { attributes: { MG_LAST_DELIVERED: event.timestamp } }); break; case 'opened': await tajo.events.track({ email, event: 'email_opened', properties: { subject: event.message.headers.subject } }); break; case 'clicked': await tajo.events.track({ email, event: 'email_clicked', properties: { url: event.url } }); break; }}
// Follow pagination for more eventsif (paging.next) { // Fetch next page using paging.next URL}Mailgun Webhooks हैंडल करें
const crypto = require('crypto');
app.post('/webhooks/mailgun', async (req, res) => { // Verify webhook signature const { timestamp, token, signature } = req.body.signature; const encodedToken = crypto .createHmac('sha256', process.env.MAILGUN_WEBHOOK_SIGNING_KEY) .update(timestamp.concat(token)) .digest('hex');
if (encodedToken !== signature) { return res.status(401).send('Unauthorized'); }
const eventData = req.body['event-data']; const event = eventData.event; const email = eventData.recipient;
await tajo.connectors.handleWebhook('mailgun', { topic: event, payload: eventData });
// Handle bounce suppression if (event === 'failed' && eventData.severity === 'permanent') { await tajo.contacts.update(email, { attributes: { MG_BOUNCE_TYPE: 'hard_bounce' }, emailBlacklisted: true }); }
res.status(200).send('OK');});Bounces और Complaints सिंक करें
// Sync bounced addresses for list hygieneconst bouncesResponse = await fetch( `https://api.mailgun.net/v3/${domain}/bounces?limit=100`, { headers: { 'Authorization': `Basic ${Buffer.from(`api:${apiKey}`).toString('base64')}` } });
const { items: bounces } = await bouncesResponse.json();
for (const bounce of bounces) { await tajo.contacts.update(bounce.address, { attributes: { MG_BOUNCE_TYPE: bounce.error.includes('550') ? 'hard_bounce' : 'soft_bounce', MG_BOUNCE_DATE: bounce.created_at }, emailBlacklisted: bounce.error.includes('550') });}दर सीमाएं
| एंडपॉइंट | सीमा | नोट्स |
|---|---|---|
| Messages API | प्लान के अनुसार | 100/hr (free), असीमित (paid) |
| Events API | कोई स्पष्ट सीमा नहीं | 300 आइटम max के साथ pagination का उपयोग करें |
| Validation API | प्लान पर आधारित | Pay-per-validation |
| Webhooks | रीयल-टाइम | डिलीवरी पर कोई दर सीमा नहीं |
| Suppressions API | कोई स्पष्ट सीमा नहीं | मानक दर सीमा लागू होती है |
Sending सीमाएं
Mailgun आपके प्लान और domain reputation के आधार पर sending सीमाएं लागू करता है। नए domains कम सीमाओं के साथ शुरू होते हैं जो आपकी sender reputation में सुधार होने पर बढ़ती हैं। Mailgun डैशबोर्ड में अपने domain आंकड़ों की निगरानी करें।
समस्या निवारण
| समस्या | कारण | समाधान |
|---|---|---|
| 401 Unauthorized | अमान्य API key | Mailgun डैशबोर्ड में API key सत्यापित करें |
| Domain सत्यापित नहीं | DNS records गायब | आवश्यक TXT, CNAME, MX records जोड़ें |
| Webhook प्राप्त नहीं हुआ | URL एक्सेस योग्य नहीं | सुनिश्चित करें कि webhook URL सार्वजनिक रूप से पहुंच योग्य है |
| इवेंट्स गायब | Time range बहुत संकीर्ण | begin/end पैरामीटर का विस्तार करें |
| कम deliverability | Domain reputation | domain आंकड़े और प्रमाणीकरण जांचें |
डीबग मोड
connectors: mailgun: debug: true log_level: verbose log_webhooks: true log_events: trueसर्वोत्तम प्रथाएं
- sending domains सत्यापित करें - इष्टतम deliverability के लिए DNS सत्यापन पूरा करें
- इवेंट्स के लिए webhooks का उपयोग करें - रीयल-टाइम webhook डिलीवरी बनाम Events API पोलिंग
- bounces को सक्रिय रूप से हैंडल करें - hard bounces को Brevo में तुरंत suppress करें
- अपने messages को tag करें - ईमेल प्रदर्शन को वर्गीकृत और विश्लेषित करने के लिए tags का उपयोग करें
- domain reputation की निगरानी करें - Mailgun डैशबोर्ड में deliverability मेट्रिक्स ट्रैक करें
- ईमेल validation का उपयोग करें - Brevo lists में जोड़ने से पहले एड्रेस मान्य करें
सुरक्षा
- HTTP Basic Auth - Authorization हेडर के माध्यम से API key प्रसारित
- Webhook सिग्नेचर - HMAC-SHA256 सिग्नेचर सत्यापन
- Domain सत्यापन - SPF, DKIM, और DMARC DNS प्रमाणीकरण
- IP whitelisting - dedicated IP प्लान्स के लिए उपलब्ध
- TLS एन्क्रिप्शन - सभी API एंडपॉइंट्स को HTTPS की आवश्यकता है
- Key rotation - Mailgun डैशबोर्ड के माध्यम से समय-समय पर API keys रोटेट करें