feat: Read mail credentials from env

Close #1
This commit is contained in:
Niklas Meinzer
2025-02-15 12:37:05 +01:00
parent 848122de02
commit 96c673f837

23
main.py
View File

@@ -1,8 +1,10 @@
import argparse
import os
import secrets
import smtplib
import string
import subprocess
import sys
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@@ -106,21 +108,24 @@ def create_user(
mail_password,
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Creates Yunohost user from a csv file and sends them an email with the password",
)
parser.add_argument("filename", help="Input file name")
parser.add_argument(
"mail_user", help="This user will be used to send the confirmation mail"
)
parser.add_argument(
"mail_password", help="This password will be used to send the confirmation mail"
)
parser.add_argument("--dry-run", action="store_true")
args = parser.parse_args()
mail_password = os.environ.get("MAIL_PASSWORD", None)
mail_user = os.environ.get("MAIL_USER", None)
if mail_user is None:
print("Missing environment variable: MAIL_USER")
sys.exit(1)
if mail_password is None:
print("Missing environment variable: MAIL_PASSWORD")
sys.exit(1)
with open(args.filename, "r") as f:
data = f.readlines()
@@ -131,7 +136,7 @@ if __name__ == "__main__":
create_user(
*line.strip().split(","),
mail_text=email_text,
mail_user=args.mail_user,
mail_password=args.mail_password,
mail_user=mail_user,
mail_password=mail_password,
dry_run=args.dry_run,
)