← back to Cypress Awards

backend/EMAIL_SETUP.md

155 lines

# Email Configuration for Server Status Monitoring

The server monitoring system sends daily status reports at 6 AM to steve@designerwallcoverings.com.

## Current Status

Currently, emails are **logged to file only** at `/var/log/cypresawards_status_email.log`.

To enable actual email delivery, follow the setup instructions below.

## Setup Instructions

### Step 1: Create Configuration File

```bash
cd /root/WebsitesMisc/cypresawards/backend
cp smtp_config.example.js smtp_config.js
```

### Step 2: Choose an Email Provider

Pick one of the following options and configure accordingly:

#### Option 1: Gmail (Free, Recommended for Testing)

1. Create or use an existing Gmail account
2. Enable 2-factor authentication
3. Generate an app-specific password: https://myaccount.google.com/apppasswords
4. Edit `smtp_config.js`:

```javascript
module.exports = {
  enabled: true,
  service: 'gmail',
  auth: {
    user: 'your-email@gmail.com',
    pass: 'your-app-specific-password'
  },
  from: 'your-email@gmail.com',
  to: 'steve@designerwallcoverings.com'
};
```

#### Option 2: SendGrid (Free tier: 100 emails/day)

1. Sign up at https://sendgrid.com
2. Create an API key
3. Edit `smtp_config.js`:

```javascript
module.exports = {
  enabled: true,
  host: 'smtp.sendgrid.net',
  port: 587,
  auth: {
    user: 'apikey',
    pass: 'YOUR_SENDGRID_API_KEY'
  },
  from: 'noreply@cypresawards.com',
  to: 'steve@designerwallcoverings.com'
};
```

#### Option 3: Mailgun (Free tier: 5,000 emails/month)

1. Sign up at https://mailgun.com
2. Add and verify your domain
3. Get SMTP credentials
4. Edit `smtp_config.js`:

```javascript
module.exports = {
  enabled: true,
  host: 'smtp.mailgun.org',
  port: 587,
  auth: {
    user: 'postmaster@your-domain.mailgun.org',
    pass: 'your-mailgun-password'
  },
  from: 'noreply@cypresawards.com',
  to: 'steve@designerwallcoverings.com'
};
```

#### Option 4: Hosting Provider SMTP

Check your hosting provider's documentation for SMTP settings.

```javascript
module.exports = {
  enabled: true,
  host: 'mail.yourhost.com',
  port: 587,
  secure: false,
  auth: {
    user: 'your-username',
    pass: 'your-password'
  },
  from: 'noreply@cypresawards.com',
  to: 'steve@designerwallcoverings.com'
};
```

### Step 3: Test the Configuration

Run a test to verify email delivery:

```bash
cd /root/WebsitesMisc/cypresawards/backend
./check_server_status.sh
```

Check the output for:
- `✅ Email sent successfully to: steve@designerwallcoverings.com` (success)
- Or error messages if something is misconfigured

## Security Notes

- **Never commit `smtp_config.js` to version control** (it contains credentials)
- The `.gitignore` should exclude `smtp_config.js`
- Use environment variables for production deployments
- Rotate credentials periodically

## Monitoring

- Email logs: `/var/log/cypresawards_status_email.log`
- Script execution logs: `/var/log/cypresawards_server_check.log`
- Cron schedule: Daily at 6:00 AM (0 6 * * *)

## Troubleshooting

### "SMTP is disabled" message
- Make sure `enabled: true` in smtp_config.js

### "Authentication failed" error
- Verify credentials are correct
- For Gmail: ensure you're using an app-specific password, not your regular password
- Check if 2FA is required

### "Connection timeout" error
- Verify the host and port are correct
- Check if your server's firewall blocks outgoing SMTP connections
- Try a different port (587, 465, or 25)

### Emails go to spam
- Configure SPF, DKIM, and DMARC records for your domain
- Use a verified sender address
- Consider using a dedicated email service (SendGrid, Mailgun)

## Manual Test Command

```bash
node send_status_email.js "✅ TEST STATUS" "This is a test email from CyPresAwards monitoring"
```