API Data Provider - Online Help

Connecting to Mailgun

Using API Key Authentication

Mailgun uses API key authentication. The API key is passed as HTTP Basic authentication with the fixed username api and the API key as the password. To obtain your API key:

  1. Log in to your Mailgun account.
  2. Click the dropdown next to your account name and navigate to Account Settings > API Security.
  3. Copy an existing API key or click Create Key to generate a new one.

After obtaining your API key, set the following connection properties:

  • AuthScheme: Set this to APIKey.
  • APIKey: Set this to your Mailgun API key.
  • IsEU: Set this to true if your Mailgun domain is in the EU region. Defaults to false.

Example Connection String

Profile=C:\profiles\Mailgun.apip;AuthScheme=APIKey;APIKey=your_api_key;

Available Tables

The Mailgun API Profile provides access to the following tables:

  • Allowlists: Returns the list of allowlist records for a domain.
  • Bounces: Returns the list of bounces for a domain.
  • Complaints: Returns the list of complaints for a domain.
  • DomainKeys: Returns the list of domain keys.
  • Domains: Returns the domains configured in your Mailgun account.
  • DomainTrackingSettings: Returns open, click, and unsubscribe tracking status for a domain.
  • MailingListMembers: Returns members of a specific Mailgun mailing list.
  • MailingLists: Returns the mailing lists configured in your Mailgun account.
  • MessageQueues: Returns messages currently queued for delivery for a domain.
  • Routes: Returns the list of routes configured in your Mailgun account.
  • Subaccounts: Returns subaccounts configured under your primary Mailgun account.
  • Templates: Returns email templates for a domain.
  • TemplateVersions: Returns versions of a specific email template.
  • Unsubscribes: Returns the list of unsubscribes for a domain.
  • Users: Returns user accounts configured under your Mailgun account.
  • Webhooks: Returns all webhooks configured for a domain.

Usage Examples

Domains:

SELECT * FROM Domains
INSERT INTO Domains (Name, SpamAction, WebScheme) VALUES ('newdomain.com', 'disabled', 'https')
UPDATE Domains SET SpamAction = 'block', WebScheme = 'https' WHERE Name = 'newdomain.com'
DELETE FROM Domains WHERE Name = 'newdomain.com'

Bounces:

SELECT * FROM Bounces WHERE DomainName = 'yourdomain.com'
INSERT INTO Bounces (DomainName, Address, Code, Error) VALUES ('yourdomain.com', '[email protected]', '550', 'No such user')
DELETE FROM Bounces WHERE DomainName = 'yourdomain.com' AND Address = '[email protected]'

Complaints:

SELECT * FROM Complaints WHERE DomainName = 'yourdomain.com'
INSERT INTO Complaints (DomainName, Address) VALUES ('yourdomain.com', '[email protected]')
DELETE FROM Complaints WHERE DomainName = 'yourdomain.com' AND Address = '[email protected]'

Unsubscribes:

SELECT * FROM Unsubscribes WHERE DomainName = 'yourdomain.com'
INSERT INTO Unsubscribes (DomainName, Address) VALUES ('yourdomain.com', '[email protected]')
DELETE FROM Unsubscribes WHERE DomainName = 'yourdomain.com' AND Address = '[email protected]'

Allowlists:

SELECT * FROM Allowlists WHERE DomainName = 'yourdomain.com'
INSERT INTO Allowlists (DomainName, Value) VALUES ('yourdomain.com', '[email protected]')
DELETE FROM Allowlists WHERE DomainName = 'yourdomain.com' AND Value = '[email protected]'

MailingLists:

SELECT * FROM MailingLists
INSERT INTO MailingLists (Address, Name, AccessLevel) VALUES ('[email protected]', 'Newsletter', 'readonly')
UPDATE MailingLists SET Name = 'Weekly Newsletter', Description = 'Weekly company updates' WHERE Address = '[email protected]'
DELETE FROM MailingLists WHERE Address = '[email protected]'

MailingListMembers:

SELECT * FROM MailingListMembers WHERE ListAddress = '[email protected]'
INSERT INTO MailingListMembers (ListAddress, Address, Name, Subscribed) VALUES ('[email protected]', '[email protected]', 'John Doe', true)
UPDATE MailingListMembers SET Subscribed = false WHERE ListAddress = '[email protected]' AND Address = '[email protected]'
DELETE FROM MailingListMembers WHERE ListAddress = '[email protected]' AND Address = '[email protected]'

Routes:

SELECT * FROM Routes
INSERT INTO Routes (Expression, Actions, Priority, Description) VALUES ('match_recipient(".*@yourdomain.com")', 'forward("http://myapp.com/incoming")', 0, 'Forward all incoming messages')
UPDATE Routes SET Priority = 1, Description = 'Updated route description' WHERE Id = '5e622a27a6ea6800c1cdca88'
DELETE FROM Routes WHERE Id = '5e622a27a6ea6800c1cdca88'

Templates:

SELECT * FROM Templates WHERE DomainName = 'yourdomain.com'
INSERT INTO Templates (DomainName, Name, Description) VALUES ('yourdomain.com', 'welcome-email', 'Welcome email template')
UPDATE Templates SET Description = 'Updated welcome email template' WHERE DomainName = 'yourdomain.com' AND Name = 'welcome-email'
DELETE FROM Templates WHERE DomainName = 'yourdomain.com' AND Name = 'welcome-email'

TemplateVersions:

SELECT * FROM TemplateVersions WHERE DomainName = 'yourdomain.com' AND TemplateName = 'welcome-email'
INSERT INTO TemplateVersions (DomainName, TemplateName, Tag, Template) VALUES ('yourdomain.com', 'welcome-email', 'v1', 'Hello {{name}}, welcome!')
UPDATE TemplateVersions SET Template = 'Hello {{name}}, welcome to our service!', Comment = 'Updated greeting' WHERE DomainName = 'yourdomain.com' AND TemplateName = 'welcome-email' AND Tag = 'v1'
DELETE FROM TemplateVersions WHERE DomainName = 'yourdomain.com' AND TemplateName = 'welcome-email' AND Tag = 'v1'

Webhooks:

SELECT * FROM Webhooks WHERE DomainName = 'yourdomain.com'

DomainTrackingSettings:

SELECT * FROM DomainTrackingSettings WHERE DomainName = 'yourdomain.com'
UPDATE DomainTrackingSettings SET OpenTrackingActive = true WHERE DomainName = 'yourdomain.com'
UPDATE DomainTrackingSettings SET ClickTrackingActive = true WHERE DomainName = 'yourdomain.com'
UPDATE DomainTrackingSettings SET UnsubscribeTrackingActive = true WHERE DomainName = 'yourdomain.com'

DomainKeys:

SELECT * FROM DomainKeys WHERE DomainName = 'yourdomain.com'

MessageQueues:

SELECT * FROM MessageQueues WHERE DomainName = 'yourdomain.com'

Subaccounts:

SELECT * FROM Subaccounts
INSERT INTO Subaccounts (Name) VALUES ('my-subaccount')
DELETE FROM Subaccounts WHERE Id = 'a1b2c3d4e5f6a1b2c3d4e5f6'

Users:

SELECT * FROM Users

Connection Properties

The connection string properties are the various options that can be used to establish a connection. This section provides a complete list of the options you can configure in the connection string for this provider.


Property Description
APIKey The Mailgun API key used to authenticate requests.
AuthScheme The scheme used for authentication. Accepted entries are APIKey or None.
Allowed values are: BASIC, NONE, NTLM, OAUTH, APIKEY, OAUTH_CLIENT, OAUTH_PASSWORD
IsEU Specifies whether the Mailgun account is registered in the EU region.

Copyright (c) 2026 CData Software, Inc. - All rights reserved.
Build 26.0.9770.0