Unity SDK
The official Unity SDK for Veil Mail, built on UnityWebRequest for full cross-platform compatibility including WebGL, mobile, and desktop.
- Built on UnityWebRequest (cross-platform, WebGL compatible)
- Dual API: async/await and coroutine support
- Editor tools: Project Settings panel and Test Email window
- API key stripping for builds (security)
- Zero external dependencies (bundled JSON utility)
- Unity 2021.3 LTS or later
Why a separate Unity SDK?
The .NET SDK uses System.Net.Http.HttpClient, which does not work on WebGL or some mobile platforms with IL2CPP. This SDK uses UnityWebRequest for full cross-platform support.
Installation
Install via the Unity Package Manager using the Git URL:
// In Unity: Window > Package Manager > + > Add package from git URL
https://github.com/Resonia-Health/veilmail-unity.gitOr add directly to Packages/manifest.json:
{
"dependencies": {
"xyz.veilmail.sdk": "https://github.com/Resonia-Health/veilmail-unity.git"
}
}Quick Start
Using async/await
using System.Collections.Generic;
using UnityEngine;
using VeilMail;
public class EmailSender : MonoBehaviour
{
async void Start()
{
var client = new VeilMailClient("veil_live_xxxxx");
var result = await client.Emails.SendAsync(new Dictionary<string, object>
{
["from"] = "hello@yourdomain.com",
["to"] = "user@example.com",
["subject"] = "Hello from Unity!",
["html"] = "<h1>Welcome!</h1>",
});
Debug.Log($"Email sent! ID: {result["id"]}");
}
}Using coroutines
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VeilMail;
using VeilMail.Utilities;
public class EmailSenderCoroutine : MonoBehaviour
{
IEnumerator Start()
{
var client = new VeilMailClient("veil_live_xxxxx");
yield return client.Emails.SendAsync(new Dictionary<string, object>
{
["from"] = "hello@yourdomain.com",
["to"] = "user@example.com",
["subject"] = "Hello from Unity!",
["html"] = "<h1>Welcome!</h1>",
}).AsCoroutine(
onSuccess: result => Debug.Log($"Sent! ID: {result["id"]}"),
onError: error => Debug.LogError($"Error: {error.Message}")
);
}
}Configuration
You can configure VeilMail via code or through the editor.
Code Configuration
// Direct API key
var client = new VeilMailClient("veil_live_xxxxx");
// With options
var client = new VeilMailClient(
apiKey: "veil_live_xxxxx",
baseUrl: "https://api.veilmail.xyz",
timeoutSeconds: 30
);
// From Project Settings (editor-configured VeilMailConfig asset)
var client = VeilMailClient.FromSettings();Editor Configuration
Go to Edit > Project Settings > VeilMail to configure:
- • API Key (password-masked with show/hide toggle)
- • Base URL
- • Timeout
- • Strip API Key in Builds (recommended, enabled by default)
- • Test Connection button
Resources
The client exposes the same resources as the Node.js SDK:
| Resource | Description |
|---|---|
client.Emails | Send and manage emails |
client.Domains | Domain verification |
client.Templates | Email templates |
client.Audiences | Audience and subscriber management |
client.Campaigns | Email campaigns |
client.Webhooks | Webhook configuration |
client.Topics | Subscription topics |
client.Properties | Custom properties |
client.Sequences | Email sequences |
client.Feeds | RSS feeds |
client.Forms | Signup forms |
client.Analytics | Email analytics |
Error Handling
using VeilMail;
using VeilMail.Exceptions;
try
{
var result = await client.Emails.SendAsync(new Dictionary<string, object>
{
["from"] = "hello@yourdomain.com",
["to"] = "user@example.com",
["subject"] = "Hello",
["html"] = "<p>Content</p>",
});
}
catch (PiiDetectedException ex)
{
Debug.LogError($"PII detected: {string.Join(", ", ex.PiiTypes)}");
}
catch (RateLimitException ex)
{
Debug.LogWarning($"Rate limited. Retry after {ex.RetryAfter}s");
}
catch (AuthenticationException)
{
Debug.LogError("Invalid API key");
}
catch (VeilMailException ex)
{
Debug.LogError($"API error [{ex.ErrorCode}]: {ex.Message}");
}Editor Tools
Project Settings
Edit > Project Settings > VeilMail — Configure your API key, base URL, timeout, and build stripping options. Includes a "Test Connection" button to verify your setup.
Test Email Window
Tools > VeilMail > Send Test Email — Send test emails directly from the editor with a simple form UI.
Webhook Verification
using VeilMail.Webhook;
// Verify a webhook signature
bool isValid = WebhookVerifier.Verify(
payload: requestBody,
signature: headers["X-VeilMail-Signature"],
secret: "whsec_xxxxx"
);Security
Never ship API keys in game builds
Game clients can be decompiled and network traffic intercepted. For shipped builds, route API calls through a server proxy.
| Context | Direct API Key | Server Proxy |
|---|---|---|
| Editor tools / testing | Safe | Not needed |
| Desktop builds | Unsafe | Required |
| WebGL builds | Unsafe | Required |
| Mobile builds | Unsafe | Required |
The SDK includes a ServerProxy sample that demonstrates the proxy pattern with a minimal Express.js server.
Install from Source
Clone the repository and add it as a local package:
git clone https://github.com/Resonia-Health/veilmail-unity.git
# Then in Unity: Window > Package Manager > + > Add package from disk
# Navigate to the cloned folder and select package.json