Files
emailsystem/start_windows.ps1
2025-02-25 19:50:00 +08:00

30 lines
1.1 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 创建必要的目录
New-Item -ItemType Directory -Path "logs", "email_data", "db" -Force | Out-Null
# 检查环境变量文件是否存在,不存在则创建
if (-not (Test-Path ".env")) {
Write-Host "创建.env文件..."
$secretKey = -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 32 | ForEach-Object {[char]$_})
Set-Content -Path ".env" -Value @"
FLASK_ENV=production
SECRET_KEY=$secretKey
MAIL_DOMAINS=example.com,mail.example.com
"@
Write-Host ".env文件已创建"
}
# 初始化数据库
Write-Host "初始化数据库..."
python -c "from app.models import init_db; init_db()"
# 启动服务
Write-Host "启动服务..."
$smtpPort = if ($env:SMTP_PORT) { $env:SMTP_PORT } else { 25 }
# 检查是否以管理员权限运行25端口需要
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin -and $smtpPort -lt 1024) {
Write-Host "警告: 在端口 $smtpPort 运行SMTP服务需要管理员权限" -ForegroundColor Yellow
}
python run.py --host 0.0.0.0 --port 5000 --smtp-port $smtpPort