Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.
Go email-relayemail-routinghttp-to-smtpmail-deliverymailchimp-alternativemailgun-alternativemailsendermailservermailtemplatemailtestpostmark-alternativesend-emailsendgrid-alternativesendmailtransactional-emailtransactional-outbox
import api from './client'
import type { ApiResponse, AuthResponse, UserProfile, Setup2FAResponse, Plan } from './types'
export const authApi = {
login(email: string, password: string, twoFactorCode?: string) {
const body: Record<string, string> = { email, password }
if (twoFactorCode) body.two_factor_code = twoFactorCode
return api.post<ApiResponse<AuthResponse>>('/auth/login', body)
},
me() {
return api.get<ApiResponse<UserProfile>>('/users/me')
},
// Revokes the current session server-side and expires the session cookie.
logout() {
return api.post<ApiResponse<{ message: string }>>('/users/me/sessions/logout')
},
updateProfile(data: { name: string; require_verified_domain?: boolean }) {
return api.put<ApiResponse<UserProfile>>('/users/me', data)
},
// The workspace a request that sends no X-Posta-Workspace-Id header operates
// on. The dashboard always sends the header, so this only affects API keys,
// SDKs, and curl.
setDefaultWorkspace(workspaceId: number) {
return api.put<ApiResponse<{ message: string }>>('/users/me/default-workspace', {
workspace_id: workspaceId,
})
},
changePassword(currentPassword: string, newPassword: string) {
return api.put<ApiResponse<{ message: string }>>('/users/me/password', {
current_password: currentPassword,
new_password: newPassword,
})
},
setup2FA() {
return api.post<ApiResponse<Setup2FAResponse>>('/users/me/2fa/setup')
},
verify2FA(code: string) {
return api.post<ApiResponse<{ message: string }>>('/users/me/2fa/verify', { code })
},
disable2FA(code: string) {
return api.post<ApiResponse<{ message: string }>>('/users/me/2fa/disable', { code })
},
requestAccountDeletion() {
return api.post<ApiResponse<{ message: string; scheduled_deletion_at: string }>>('/users/me/delete')
},
cancelAccountDeletion() {
return api.post<ApiResponse<{ message: string }>>('/users/me/cancel-deletion')
},
register(name: string, email: string, password: string) {
return api.post<ApiResponse<AuthResponse>>('/auth/register', { name, email, password })
},
registrationStatus() {
return api.get<ApiResponse<{ registration_enabled: boolean; password_reset_enabled: boolean }>>('/auth/registration-status')
},
forgotPassword(email: string) {
return api.post<ApiResponse<{ message: string }>>('/auth/forgot-password', { email })
},
resetPassword(token: string, newPassword: string) {
return api.post<ApiResponse<{ message: string }>>('/auth/reset-password', { token, new_password: newPassword })
},
verifyEmail(token: string) {
return api.get<ApiResponse<{ message: string }>>(`/auth/verify-email?token=${encodeURIComponent(token)}`)
},
resendVerificationEmail() {
return api.post<ApiResponse<{ message: string }>>('/users/me/verify-email/resend')
},
getMyPlan() {
return api.get<ApiResponse<Plan | null>>('/users/me/plan')
},
}