Add flexible authentication: email or username can be optional

Key improvements:
- Either email OR username can be empty (but not both)
- Enhanced validation logic for authentication methods
- Improved error messages showing available auth methods
- More flexible IMAPConnection constructor with better defaults

Authentication options:
1. Email-only: SOURCE_EMAIL=user@domain.de, SOURCE_USERNAME=
2. Username-only: SOURCE_EMAIL=, SOURCE_USERNAME=username123
3. Both (fallback): Provide both for automatic fallback
4. Dual method: Username tried first, email as fallback

Configuration updates:
- Update .env.template with all four authentication examples
- Clarify requirements and optional nature of fields
- Add comprehensive authentication scenarios

Documentation updates:
- Expand README with four authentication options
- Add troubleshooting for different auth combinations
- Clarify flexible requirements (either email OR username required)

This makes the script compatible with even more email providers and hosting scenarios.
This commit is contained in:
Elmar Sönser 2025-09-24 14:21:06 +02:00
commit c8ca753c04
3 changed files with 77 additions and 21 deletions

View file

@ -27,23 +27,37 @@ A Python script to migrate emails from one IMAP account to another with flexible
## Authentication Methods
The script supports two authentication methods and automatically tries both:
The script supports flexible authentication with four possible configurations:
### Method 1: Email-based Login (Most Common)
### Option 1: Email-based Login (Most Common)
```env
SOURCE_EMAIL=user@domain.de
SOURCE_USERNAME=
```
**Used by**: Gmail, Yahoo, Outlook, most modern providers
### Method 2: Username-based Login
### Option 2: Username + Email (Dual Method)
```env
SOURCE_EMAIL=user@domain.de
SOURCE_USERNAME=mail_user123
```
**Used by**: Some hosting providers, older email systems, cPanel hosting
**Used by**: Some hosting providers - tries username first, falls back to email
The script automatically tries username first (if provided), then falls back to email authentication.
### Option 3: Username-only Login
```env
SOURCE_EMAIL=
SOURCE_USERNAME=mail_user123
```
**Used by**: Legacy systems, some cPanel hosting where email is unknown
### Option 4: Email-only Login
```env
SOURCE_EMAIL=user@domain.de
SOURCE_USERNAME=
```
**Used by**: When you're certain email authentication is the only method
**Requirements**: You must provide either SOURCE_EMAIL or SOURCE_USERNAME (or both). Same applies to destination settings.
## Import Folder Options
@ -235,7 +249,10 @@ Errors encountered: 0
### Common Issues
**Authentication Failed**
- Check if username is required (try both with and without `SOURCE_USERNAME`)
- Try different authentication combinations:
- Email only: Set `SOURCE_USERNAME=` (empty)
- Username only: Set `SOURCE_EMAIL=` (empty)
- Both: Provide both values for fallback
- Verify server address from your hosting provider
- For Host Europe: Get exact server name from KIS panel
- For Gmail/Yahoo: Use app passwords, not regular passwords
@ -248,7 +265,10 @@ Errors encountered: 0
- Verify server address and port
**Username vs Email Login Issues**
- Try leaving `SOURCE_USERNAME` empty to use email login
- Try all combinations:
1. Email only: `SOURCE_EMAIL=user@domain.de`, `SOURCE_USERNAME=`
2. Username only: `SOURCE_EMAIL=`, `SOURCE_USERNAME=username123`
3. Both (fallback): Provide both values
- For Host Europe: Check if Easy-Mail-Login is enabled
- Contact your hosting provider for authentication method
- Check provider documentation for login format