This guide explains how to use the web-based user interface for testing Mandrill email sending features.
The web UI provides an easy-to-use interface for testing all Mandrill email features without running Ruby scripts directly from the command line. Built with Sinatra, it offers a modern, responsive design.
# Install all required gems including web server dependencies
cd scripts
bundle installMake sure your .env file is configured in the scripts directory:
cd scripts
cp env.example .envEdit the .env file with your credentials:
MANDRILL_API_KEY=your_mandrill_api_key_here
DEFAULT_FROM_EMAIL=sender@yourdomain.com
DEFAULT_FROM_NAME="Your Name"
DEFAULT_TO_EMAIL=recipient@example.com
DEFAULT_TO_NAME="Recipient Name"Note: Always quote values that contain spaces or special characters.
From the project root directory:
# Navigate to scripts directory
cd scripts
# Option 1: Direct execution
ruby app.rb
# Option 2: With Bundler (recommended)
bundle exec ruby app.rbYou should see:
============================================================
🚀 Mandrill Email Demo Web Application
============================================================
📧 Starting web server...
🌐 Open your browser to: http://localhost:4567
💡 Press Ctrl+C to stop the server
Navigate to:
http://localhost:4567
The web UI provides access to all five email sending operations:
- Basic email sending demonstration
- Uses values from your
.envconfiguration - Perfect for testing basic setup
- Dynamic form fields for personalization
- Enter: First Name, Last Name, Company Name, Membership Level
- Demonstrates dynamic content replacement
- Sends emails with file attachments
- Demo includes PDF, CSV, and text files
- Shows base64 encoding in action
- Choose between two pre-defined templates
- Visual template preview
- Demonstrates template-based email sending
- Comprehensive demo of all features combined
- Attachments, merge tags, metadata, tracking, etc.
- Shows the full power of the Mandrill API
The home page displays:
- Dropdown Menu: Select which email operation to test
- Description Box: Dynamic description of the selected operation
- Conditional Inputs: Form fields appear based on your selection
- Generate Button: Triggers the email sending process
- Input fields for First Name, Last Name, Company Name, and Membership Level
- All fields are required
- Values are passed to the email script as environment variables
- Radio buttons to select between Template 1 and Template 2
- Visual preview of each template
- Shows how merge tags will be replaced
- Info box explaining what attachments will be included
- No additional input required
After sending an email:
- Success Message: Green banner with success status
- Error Message: Red banner with error details
- Call to Action: Reminder to check your inbox
sampleapp-mandrill-mailchimp-transactional-ruby/
├── views/
│ └── index.erb # HTML template
├── public/
│ └── styles.css # CSS styles
├── scripts/
│ ├── app.rb # Main Sinatra application
│ ├── Gemfile # Ruby dependencies
│ ├── .env # Environment variables
│ ├── email_with_single_recipient.rb
│ ├── email_with_merge_tags.rb
│ ├── email_with_attachments.rb
│ ├── email_with_template.rb
│ └── kitchen_sink_email.rb
└── WEB_UI_GUIDE.md # This file
- Web Framework: Sinatra 4.0
- Template Engine: ERB (Embedded Ruby)
- Web Server: WEBrick (built-in)
- CSS: Custom responsive design
- JavaScript: Vanilla JS for form interactions
- User Selection: User selects an operation from the dropdown
- Dynamic UI: JavaScript shows/hides relevant form fields
- Form Submission: Form data is POST-ed to
/testEmailbasedOnScriptID - Script Execution: Ruby backend executes the corresponding script
- Result Display: Success/error message is shown to the user
The web app passes data to scripts via environment variables:
For Merge Tags:
ENV['MERGE_FIRST_NAME']
ENV['MERGE_LAST_NAME']
ENV['MERGE_COMPANY_NAME']
ENV['MERGE_MEMBERSHIP_LEVEL']For Templates:
ENV['SELECTED_TEMPLATE'] - Select "1. Send a Single Email to a Single Recipient"
- Read the description
- Click "Generate Test Email"
- Check inbox at the email configured in
.env
- Select "2. Send Email with Merge Tags"
- Fill in the form:
- First Name: John
- Last Name: Doe
- Company Name: Acme Corp
- Membership Level: Gold
- Click "Generate Test Email"
- Email will be personalized with your values
- Select "4. Send Email Using Template"
- Choose Template 1 or Template 2 by clicking the radio button
- Review the template preview
- Click "Generate Test Email"
- Email will use the selected template
Error: cannot load such file -- sinatra
# Solution: Install dependencies
bundle installError: Address already in use
# Solution: Port 4567 is already in use. Kill the existing process:
lsof -ti:4567 | xargs kill -9Check your .env file:
# Verify your credentials are correct
cat scripts/.envCheck script output:
- The web UI shows the actual script output in the error message
- Look for specific API errors or configuration issues
Common Issues:
- Invalid API key
- Missing environment variables
- Invalid email addresses in
.env
Merge Tags fields not accepting input:
- Make sure JavaScript is enabled in your browser
- Try refreshing the page
Template selection not working:
- Check browser console for JavaScript errors
- Ensure CSS is loading correctly
For production use, consider:
- Authentication: Add user authentication (Devise, etc.)
- Rate Limiting: Prevent abuse with rate limiting
- Input Validation: Sanitize all user inputs
- HTTPS: Use SSL/TLS in production
- Error Handling: Don't expose sensitive errors to users
- Environment Variables: Use secure secret management
- CORS: Configure appropriate CORS policies
- Form validation (client-side and server-side)
- Environment variable isolation
- No sensitive data in URLs
- Proper error handling
The UI is fully responsive and works on:
- 🖥️ Desktop computers
- 💻 Laptops
- 📱 Tablets
- 📱 Mobile phones
The layout automatically adjusts for optimal viewing on any screen size.
Edit app.rb:
set :port, 4567 # Change to your preferred portEdit public/styles.css to customize:
- Colors
- Fonts
- Layout
- Animations
- Add the option to the dropdown in
views/index.erb - Add the route handler in
app.rb - Create the corresponding Ruby script in
scripts/
- Keep the server running while testing multiple operations
- Check the console output for detailed error messages
- Use the browser's Developer Tools to debug JavaScript issues
- Test with valid email addresses in your
.envfile - Review email deliverability if emails go to spam
Once you're comfortable with the web UI:
- Explore the Ruby scripts to understand the underlying code
- Modify templates to create your own email layouts
- Integrate into your application using the scripts as a reference
- Add custom features like scheduling, queuing, etc.
Ready to test your emails?
ruby app.rb
# Open http://localhost:4567 in your browserHappy emailing! 📧✨