Spaces:
Sleeping
Sleeping
File size: 6,346 Bytes
c024705 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
#!/usr/bin/env python3
"""
Email Configuration Setup Script for AIMHSA
"""
import os
import getpass
def setup_email_config():
"""Interactive setup for email configuration"""
print("=" * 60)
print("π§ AIMHSA - Email Configuration Setup")
print("=" * 60)
print()
# Check if .env file already exists
if os.path.exists('.env'):
print("β οΈ .env file already exists!")
choice = input("Do you want to overwrite it? (y/n): ").lower().strip()
if choice not in ['y', 'yes']:
print("β Setup cancelled.")
return
print("Choose your email provider:")
print("1. Gmail (Recommended)")
print("2. Outlook/Hotmail")
print("3. Yahoo Mail")
print("4. Custom SMTP Server")
print()
choice = input("Enter your choice (1-4): ").strip()
if choice == "1":
setup_gmail()
elif choice == "2":
setup_outlook()
elif choice == "3":
setup_yahoo()
elif choice == "4":
setup_custom()
else:
print("β Invalid choice. Setup cancelled.")
return
def setup_gmail():
"""Setup Gmail configuration"""
print("\nπ§ Gmail Configuration")
print("-" * 30)
email = input("Enter your Gmail address: ").strip()
if not email or '@gmail.com' not in email:
print("β Invalid Gmail address.")
return
print("\nπ Gmail App Password Setup:")
print("1. Go to your Google Account settings")
print("2. Enable 2-Factor Authentication")
print("3. Generate an 'App Password' for this application")
print("4. Use the 16-character app password (not your regular password)")
print()
password = getpass.getpass("Enter your Gmail App Password: ")
if not password:
print("β Password is required.")
return
from_email = input("From email address (default: noreply@aimhsa.rw): ").strip()
if not from_email:
from_email = "noreply@aimhsa.rw"
# Create .env content
env_content = f"""# AIMHSA Email Configuration - Gmail
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME={email}
SMTP_PASSWORD={password}
FROM_EMAIL={from_email}
# Chat Model Configuration
CHAT_MODEL=llama3.2:3b
EMBED_MODEL=nomic-embed-text
SENT_EMBED_MODEL=nomic-embed-text
"""
save_env_file(env_content, "Gmail")
def setup_outlook():
"""Setup Outlook configuration"""
print("\nπ§ Outlook/Hotmail Configuration")
print("-" * 30)
email = input("Enter your Outlook/Hotmail address: ").strip()
if not email or ('@outlook.com' not in email and '@hotmail.com' not in email):
print("β Invalid Outlook/Hotmail address.")
return
password = getpass.getpass("Enter your password: ")
if not password:
print("β Password is required.")
return
from_email = input("From email address (default: noreply@aimhsa.rw): ").strip()
if not from_email:
from_email = "noreply@aimhsa.rw"
env_content = f"""# AIMHSA Email Configuration - Outlook
SMTP_SERVER=smtp-mail.outlook.com
SMTP_PORT=587
SMTP_USERNAME={email}
SMTP_PASSWORD={password}
FROM_EMAIL={from_email}
# Chat Model Configuration
CHAT_MODEL=llama3.2:3b
EMBED_MODEL=nomic-embed-text
SENT_EMBED_MODEL=nomic-embed-text
"""
save_env_file(env_content, "Outlook")
def setup_yahoo():
"""Setup Yahoo configuration"""
print("\nπ§ Yahoo Mail Configuration")
print("-" * 30)
email = input("Enter your Yahoo Mail address: ").strip()
if not email or '@yahoo.com' not in email:
print("β Invalid Yahoo Mail address.")
return
print("\nπ Yahoo App Password Setup:")
print("1. Go to your Yahoo Account settings")
print("2. Enable 2-Factor Authentication")
print("3. Generate an 'App Password' for this application")
print()
password = getpass.getpass("Enter your Yahoo App Password: ")
if not password:
print("β Password is required.")
return
from_email = input("From email address (default: noreply@aimhsa.rw): ").strip()
if not from_email:
from_email = "noreply@aimhsa.rw"
env_content = f"""# AIMHSA Email Configuration - Yahoo
SMTP_SERVER=smtp.mail.yahoo.com
SMTP_PORT=587
SMTP_USERNAME={email}
SMTP_PASSWORD={password}
FROM_EMAIL={from_email}
# Chat Model Configuration
CHAT_MODEL=llama3.2:3b
EMBED_MODEL=nomic-embed-text
SENT_EMBED_MODEL=nomic-embed-text
"""
save_env_file(env_content, "Yahoo")
def setup_custom():
"""Setup custom SMTP configuration"""
print("\nπ§ Custom SMTP Configuration")
print("-" * 30)
server = input("Enter SMTP server: ").strip()
if not server:
print("β SMTP server is required.")
return
port = input("Enter SMTP port (default: 587): ").strip()
if not port:
port = "587"
username = input("Enter SMTP username: ").strip()
if not username:
print("β Username is required.")
return
password = getpass.getpass("Enter SMTP password: ")
if not password:
print("β Password is required.")
return
from_email = input("From email address (default: noreply@aimhsa.rw): ").strip()
if not from_email:
from_email = "noreply@aimhsa.rw"
env_content = f"""# AIMHSA Email Configuration - Custom SMTP
SMTP_SERVER={server}
SMTP_PORT={port}
SMTP_USERNAME={username}
SMTP_PASSWORD={password}
FROM_EMAIL={from_email}
# Chat Model Configuration
CHAT_MODEL=llama3.2:3b
EMBED_MODEL=nomic-embed-text
SENT_EMBED_MODEL=nomic-embed-text
"""
save_env_file(env_content, "Custom SMTP")
def save_env_file(content, provider):
"""Save .env file with configuration"""
try:
with open('.env', 'w') as f:
f.write(content)
print(f"\nβ
{provider} configuration saved to .env file!")
print("\nπ Next Steps:")
print("1. Restart your Flask application")
print("2. Test the forgot password functionality")
print("3. Check the logs for email sending status")
print("\nπ Security Note: Never commit .env files to version control!")
except Exception as e:
print(f"β Error saving .env file: {e}")
if __name__ == "__main__":
setup_email_config()
|