How to keep your Postmark account secure: Best practices guide
Your Postmark API tokens are the keys to your email kingdom. One exposed token can mean unauthorized access to your account, potential data breaches, and a whole lot of stress you don't need. The good news? Keeping your account secure doesn't have to be complicated.
This guide covers the essential practices that'll help you sleep better at night, knowing your Postmark credentials are locked down tight.
Important: While we use specific tools and languages in our examples (primarily Node.js/JavaScript), these security principles apply universally. Whether you're using Python with Django, Ruby on Rails, Go, PHP, .NET, or containerized deployments with Docker and Kubernetes, adapt these concepts to your specific technology stack and deployment environment.
Following Industry Standards: OWASP Guidelines #
When it comes to web application security, you don't have to reinvent the wheel. The Open Web Application Security Project (OWASP) provides comprehensive, industry-standard guidance that's trusted by security professionals worldwide.
The OWASP Web Security Testing Guide #
The OWASP Web Security Testing Guide is an essential resource for developers who want to build secure applications. While it covers much more than just secret management, several sections are particularly relevant to protecting your Postmark credentials:
Key areas that apply to API security:
- Authentication Testing - Ensuring your API tokens are properly validated
- Configuration and Deployment Management Testing - Securing your deployment pipeline
- Data Validation Testing - Validating inputs that might expose credentials
- Error Handling - Ensuring error messages don't leak sensitive information
Applying OWASP Principles to Your Email Infrastructure #
Here's how OWASP best practices translate to protecting your Postmark setup:
Secure Configuration Management: Follow OWASP's guidance on configuration security by keeping all sensitive Postmark credentials in dedicated secrets management tools, never in code repositories.
Why OWASP Matters for Email Security #
Email infrastructure is often overlooked in security assessments, but it's a critical attack vector. A compromised email service can lead to:
- Account takeover attacks through password reset emails
- Data exfiltration via email forwarding
- Social engineering attacks using legitimate email channels
- Compliance violations if sensitive data is transmitted insecurely
By following OWASP guidelines alongside the Postmark-specific practices in this guide, you're building defense in depth that protects both your email infrastructure and your broader application.
Code repository security: Your first line of defense #
Note: The examples below focus primarily on Node.js/JavaScript, but these concepts apply to most languages and frameworks. Adapt these approaches to your specific tech stack – whether you're using Python, Ruby, Go, Docker containers, or any other setup.
Store secrets in environment variables #
Never hardcode your Postmark API tokens directly in your source files. We've all been tempted to do it "just for now" during development, but that's how accidents happen.
Do this instead:
JavaScript
// ❌ Don't do this
const postmark = require('postmark')('your-api-token-here');
// ✅ Do this
const postmark = require('postmark')(process.env.POSTMARK_API_TOKEN);
Loading environment variables in Node.js #
For Node.js 20.6.0 and later: Modern Node.js versions have built-in support for .env files using the --env-file flag:
bash
node --env-file=.env your-app.js
For earlier Node.js versions: Use the popular dotenv package:
npm install dotenv
Then load it early in your application:
require('dotenv').config();
// Now process.env.POSTMARK_API_TOKEN is available
For local development, create a .env file in your project root:
POSTMARK_API_TOKEN=your-token-here
POSTMARK_SERVER_TOKEN=your-server-token-here
Pro tip: Add your .env file to .gitignore immediately. Future you will thank you.
Other language examples #
The concept applies universally – here are quick examples:
# Python
import os
token = os.environ.get('POSTMARK_API_TOKEN')
# Ruby
token = ENV['POSTMARK_API_TOKEN']
// Go
token := os.Getenv("POSTMARK_API_TOKEN")
Keep configuration files separate #
Create dedicated configuration files for sensitive data and exclude them from version control. Your .gitignore should include:
.env
.env.local
.env.production
config/secrets.json
config/database.yml
Set up Git hooks that actually help #
Pre-commit hooks can catch secrets before they make it into your repository. Tools like git-secrets or pre-commit can scan for common patterns:
# Install git-secrets
git secrets --install
git secrets --register-aws
git secrets --add 'POSTMARK_[A-Z_]+.*'
Secret management tools: level up your security #
Consult with security and platform teams #
Before diving into specific tools, have a conversation with your security, platform, and DevOps teams. They likely have established security strategies, approved tools, and compliance requirements that your Postmark implementation should align with.
What might seem like a simple API token to you could be part of a broader security framework that includes:
- Company-wide secret rotation policies
- Approved secret management platforms
- Compliance requirements (SOC 2, GDPR, HIPAA, etc.)
- Existing CI/CD security integrations
- Audit logging requirements
Start by asking:
- What secret management tools are already approved and supported?
- Are there existing patterns for API credential management?
- What are the compliance or audit requirements for email infrastructure?
- How should we integrate with existing monitoring and alerting systems?
This conversation upfront can save you from having to retrofit security measures later.
Use dedicated secret managers #
If you're running production applications, consider using dedicated secret management services:
- HashiCorp Vault for on-premises solutions
- AWS Secrets Manager if you're in the AWS ecosystem
- Azure Key Vault for Microsoft based Azure cloud applications
- Google Secret Manager for Google Cloud Platform
These services provide secure storage, automatic rotation, and audit trails for your sensitive credentials.
Integrate with your CI/CD pipeline #
Configure your deployment pipeline to inject secrets at build or deploy time:
# GitHub Actions example
- name: Deploy to production
env:
POSTMARK_API_TOKEN: ${{ secrets.POSTMARK_API_TOKEN }}
run: npm run deploy
Local development made simple #
Tools like direnv automatically load environment variables when you enter a project directory, making local development seamless without compromising security.
Detection and prevention: Catching problems early #
Implement automated scanning #
Use tools that scan for exposed credentials:
- GitLeaks - Scans git repositories for secrets
- TruffleHog - Searches through git history for high-entropy strings
- GitHub Secret Scanning - Automatically detects known secret formats
Make code reviews your safety net #
Train your team to spot hardcoded secrets during code reviews. Create a checklist that includes:
- Are there any hardcoded API tokens or passwords?
- Are configuration files properly excluded from version control?
- Are environment variables used for all sensitive data?
Regular security audits #
Schedule periodic scans of your existing codebases, especially older repositories that might predate your current security practices.
Development practices that keep you safe #
Official libraries and repositories #
Make sure you're only using official Postmark repositories and libraries:
- API documentation
- Official libraries and SDKs
- Official Postmark MCP - Github
- Support channels or email security@activecampaign.com if you have questions
Follow the principle of least privilege #
Use Postmark's server structure to isolate environments and control access.
Setup dedicated servers for development, staging and production. Each server will have a unique API key and only the production server will have full sending capabilities. This approach provides granular control over sending permissions while maintaining clear separation between environments
- Development server: Dedicated server configured to use sandbox mode
- Staging server: Mirror of production server configuration but also configured to use sandbox mode
- Production server: Full sending capabilities with tightly controlled API token access
Rotate your credentials regularly #
Set up a schedule for rotating your Postmark API tokens:
- Generate new tokens in your Postmark account
- Update them in your secret management system
- Deploy the changes
- Revoke the old tokens
Important: Always test the new tokens in a non-production environment first.
Create Template Configuration Files #
Provide example configuration files that show the structure without actual secrets:
// config.example.json
{
"postmark": {
"serverToken": "POSTMARK_SERVER_TOKEN_HERE",
"accountToken": "POSTMARK_ACCOUNT_TOKEN_HERE"
},
"database": {
"host": "DATABASE_HOST_HERE",
"password": "DATABASE_PASSWORD_HERE"
}
}
This helps new team members understand what credentials they need without exposing real values.
When things go wrong: Remediation steps #
Despite your best efforts, secrets sometimes get exposed. Here's your emergency playbook:
Step 1: Revoke the exposed keys immediately #
This is your highest priority. Log into your Postmark account and:
- Navigate to your API tokens section
- Revoke the compromised token
- Generate a new token
- Update your applications with the new token
Time matters here. Don't wait to investigate how it happened – secure first, investigate later.
Step 2: Remove from repository #
Delete the secret from your current codebase and commit the change:
git add .
git commit -m "Remove exposed API token"
git push
Remember: The secret still exists in your git history.
Step 3: Clean up Git history (if necessary) #
For public repositories or highly sensitive credentials, you may need to rewrite history:
# Using git filter-repo (recommended)
git filter-repo --replace-text secrets.txt
# Or using BFG Repo-Cleaner
java -jar bfg.jar --replace-text secrets.txt
Warning: This is complex and affects all contributors. Everyone will need to re-clone the repository. Github has additional guidance here.
Step 4: Coordinate with your team #
If you need to rewrite history:
- Notify all team members
- Have them back up any local changes
- Force push the cleaned repository
- Have team members re-clone
Step 5: Use platform-specific tools #
GitHub and GitLab offer built-in tools for handling exposed secrets:
- GitHub: "Remove sensitive data" feature in repository settings
- GitLab: Repository cleanup options in the project settings
Proper Error Handling: When your application encounters Postmark API errors, log them securely without exposing your API tokens or other sensitive information in logs that might be accessible to unauthorized users.
Regular Security Testing: Use OWASP's testing methodologies to regularly audit how your application handles Postmark credentials, especially during authentication failures or API rate limiting scenarios.
Making security the easy choice #
The key to good security is making secure practices the path of least resistance. When it's easier to do the right thing than the wrong thing, your team will naturally make better choices.
Set up your development environment so that:
- Environment variables are the default way to handle configuration
- Secrets are never committed to version control
- New team members can get started quickly without compromising security
Your security checklist #
Here's a quick checklist to audit your current setup:
The Bottom Line #
Securing your Postmark account isn't about implementing every possible security measure – it's about building sustainable practices that protect you without slowing down your development process.
Start with the basics: environment variables, proper .gitignore configuration, and team awareness. As your application grows, add more sophisticated tools like secret managers and automated scanning.
Your users trust you with their email communications. These practices help ensure that trust is well-placed.
Need help with Postmark security settings? Check out our security documentation or reach out to our support team. We're here to help you keep your account secure.