authenticationSuccess
The authenticationSuccess webhook event is triggered when an email account successfully authenticates with the mail server or email API. This event helps you monitor account health and confirm that previously problematic accounts have recovered.
When This Event is Triggered
The authenticationSuccess event fires when:
- An account successfully establishes an IMAP session for the first time after being added
- An account recovers from a previous authentication error state
- An account reconnects after being in a disconnected or errored state
This event is not sent on every successful connection. EmailEngine tracks connection history and only sends this webhook when:
- The account has never successfully connected before (initial connection)
- The account was previously in an error state (
authenticationErrororconnectError) and has now recovered
This intelligent filtering prevents webhook spam during normal reconnection cycles.
Common Use Cases
- Account activation tracking - Confirm that newly added accounts are working
- Error recovery monitoring - Know when previously failing accounts recover
- Dashboard updates - Update account status from "error" to "connected" in your UI
- Workflow triggers - Start processing emails only after successful authentication
- Compliance logging - Track account connectivity history for auditing
- User notifications - Inform users that their email connection has been restored
Payload Schema
Top-Level Fields
| Field | Type | Required | Description |
|---|---|---|---|
serviceUrl | string | No | The configured EmailEngine service URL |
account | string | Yes | Account ID that successfully authenticated |
date | string | Yes | ISO 8601 timestamp when the webhook was generated |
event | string | Yes | Event type, always "authenticationSuccess" for this event |
data | object | Yes | Authentication details object (see below) |
Authentication Data Fields (data object)
| Field | Type | Required | Description |
|---|---|---|---|
user | string | Yes | The email address or username used for authentication |
Example Payload
{
"serviceUrl": "https://emailengine.example.com",
"account": "user123",
"date": "2025-10-17T06:49:22.157Z",
"event": "authenticationSuccess",
"data": {
"user": "user@example.com"
}
}
Example Payload (Gmail API Account)
For accounts using Gmail API with OAuth2:
{
"serviceUrl": "https://emailengine.example.com",
"account": "gmail-user456",
"date": "2025-10-17T08:15:30.000Z",
"event": "authenticationSuccess",
"data": {
"user": "user@gmail.com"
}
}
Example Payload (Outlook Account)
For accounts using Microsoft Graph API or Outlook IMAP with OAuth2:
{
"serviceUrl": "https://emailengine.example.com",
"account": "outlook-user789",
"date": "2025-10-17T09:30:45.000Z",
"event": "authenticationSuccess",
"data": {
"user": "user@outlook.com"
}
}
Handling the Event
Basic Handler
async function handleAuthenticationSuccess(event) {
const { account, data, date } = event;
console.log(`Account ${account} authenticated successfully`);
console.log(` User: ${data.user}`);
console.log(` Time: ${date}`);
// Update account status in your system
await updateAccountStatus(account, 'connected');
}
Updating Account Status in Database
async function handleAuthenticationSuccess(event) {
const { account, data, date } = event;
// Update account status in your database
await db.accounts.update({
where: { emailEngineId: account },
data: {
status: 'connected',
lastConnectedAt: new Date(date),
lastError: null,
lastErrorCode: null,
lastErrorAt: null
}
});
// Clear any pending error notifications
await clearAccountAlerts(account);
}
Handling Recovery from Errors
async function handleAuthenticationSuccess(event) {
const { account, data, date } = event;
// Check if this account was previously in error state
const accountRecord = await db.accounts.findUnique({
where: { emailEngineId: account }
});
if (accountRecord?.status === 'authentication_error') {
// Account has recovered - notify relevant parties
console.log(`Account ${account} recovered from authentication error`);
await sendNotification({
type: 'account_recovered',
account,
message: `Email account ${data.user} is now connected`,
previousStatus: accountRecord.status,
recoveredAt: date
});
}
// Update status regardless
await db.accounts.update({
where: { emailEngineId: account },
data: {
status: 'connected',
lastConnectedAt: new Date(date)
}
});
}
Triggering Post-Authentication Workflows
async function handleAuthenticationSuccess(event) {
const { account, data, date } = event;
// Check if this is the initial connection
const isNewAccount = await checkIfNewAccount(account);
if (isNewAccount) {
// Trigger initial setup workflows
await startInitialSync(account);
await setupAccountFilters(account);
await notifyUser(account, 'Your email account is now connected');
}
// Log successful authentication
await auditLog.create({
event: 'authentication_success',
account,
user: data.user,
timestamp: date
});
}
Event Sequence
When a new account is added, you will typically receive webhooks in this order:
accountAdded- Account is registered with EmailEngineauthenticationSuccess- Account successfully authenticatesaccountInitialized- Initial mailbox sync is complete
When an account recovers from an error:
- (Previous)
authenticationError- Authentication failed - (Later)
authenticationSuccess- Authentication succeeded after recovery
Related Events
- authenticationError - Triggered when authentication fails
- connectError - Triggered when connection fails (network-level, not authentication)
- accountAdded - Triggered when a new account is registered
- accountInitialized - Triggered when initial sync completes
See Also
- Webhooks Overview - Complete webhook setup guide
- Account Management - Managing email accounts
- Gmail OAuth2 Setup - Setting up Gmail with OAuth2
- Outlook OAuth2 Setup - Setting up Outlook with OAuth2
- Troubleshooting - Common issues and solutions