refactor: switch from Mailgun to AhaSend for email notifications

- Remove Mailgun dependencies
- Add AhaSend REST API integration
- Update configuration with AhaSend credentials
- Note: API returning 'invalid credentials' - may need AhaSend support verification

Credentials configured:
- Account ID: 8a14f9a5-6e6d-47c9-b5d6-a687265b36a3
- API Key: aha-sk-A0c9WOA8cs3RpvkAGwHOP9o6pHx-gLTUki1gSWVeC_6kd86-Npn077zta-rvg9oo
This commit is contained in:
2025-11-17 00:53:20 +00:00
parent b48d52fcf3
commit e05062da99
8 changed files with 1963 additions and 87 deletions

View File

@@ -27,7 +27,7 @@ The notification system enables real-time user engagement by notifying users abo
- **cleanupOldNotifications**: Remove read notifications older than 30 days
#### EmailService (`server/src/services/emailService.ts`)
- **Mailgun Integration**: Uses Mailgun API for email delivery
- **AhaSend Integration**: Uses AhaSend REST API for email delivery
- **sendEmail**: Generic email sending function
- **sendNotificationEmail**: Formatted notification emails with HTML templates
- **testConnection**: Verify email configuration
@@ -99,25 +99,27 @@ FRONTEND_URL="http://localhost:5173"
TEST_EMAIL="test@example.com"
```
### Mailgun Setup
### AhaSend Setup
1. **API Key**: `dd27be7a81dd7b0980ada31fec9a9bd9-e80d8b76-fd80c63b`
2. **Domain**: `sandbox1835a1917b07443f8c1ca858689c42ea.mailgun.org`
3. **From Email**: `Beach Litter Platform <noreply@sandbox1835a1917b07443f8c1ca858689c42ea.mailgun.org>`
1. **API Key**: Get your API key from AhaSend dashboard
2. **From Email**: `Beach Litter Platform <noreply@beachlitter.ie>`
3. **API Endpoint**: `https://api.ahasend.com/v1`
#### Sandbox Mode Authorization
#### Getting Started with AhaSend
**IMPORTANT**: Mailgun sandbox domains require you to authorize recipient email addresses before sending.
1. Sign up at https://ahasend.com/
2. Verify your sending domain
3. Get your API key from the dashboard
4. Add the API key to your `.env` file:
```env
AHASEND_API_KEY="your_api_key_here"
```
To authorize recipients:
1. Go to https://app.mailgun.com/
2. Navigate to Sending → Domains
3. Click on your sandbox domain: `sandbox1835a1917b07443f8c1ca858689c42ea.mailgun.org`
4. Go to "Authorized Recipients" section
5. Add email addresses you want to test with (e.g., `psbailey31@gmail.com`)
6. Recipients will receive a confirmation email - they must click the link to authorize
**For Production**: Use a verified custom domain instead of sandbox to send to any email address without authorization.
**Benefits of AhaSend**:
- No sandbox restrictions - send to any email
- Simple REST API integration
- Good deliverability rates
- Straightforward pricing
## Testing
@@ -231,16 +233,13 @@ Emails include:
### Emails Not Sending
1. **Check Mailgun API key is correct**: Verify in `.env` file
2. **Verify domain is configured**: Should be `sandbox1835a1917b07443f8c1ca858689c42ea.mailgun.org`
3. **Authorize recipients for sandbox**:
- Go to https://app.mailgun.com/
- Navigate to your sandbox domain
- Add authorized recipients (they must confirm via email)
- Error "Forbidden" means recipient is not authorized
4. **Review server logs**: Check for detailed error messages
5. **Test email service**: Run `npx tsx src/scripts/testEmail.ts`
6. **For production**: Use a verified custom domain to avoid sandbox restrictions
1. **Check AhaSend API key is correct**: Verify in `.env` file
2. **Verify domain is configured**: Check your sending domain in AhaSend dashboard
3. **Check API response**: Review error messages in server logs
4. **Verify email format**: Ensure from/to emails are valid
5. **Review server logs**: Check for detailed error messages
6. **Test email service**: Run `npx tsx src/scripts/testEmail.ts`
7. **Check AhaSend status**: Visit AhaSend dashboard for account status
### Notifications Not Appearing