import subprocess
to = input("mail : ")
subject = "Test Email"
body = "Hello! This is a test email sent via sendmail."
# Prepare the email
email_text = f"""To: {to}
Subject: {subject}
Content-Type: text/plain; charset=UTF-8
{body}
"""
# Send via sendmail
process = subprocess.Popen(
["/usr/sbin/sendmail", "-t"],
stdin=subprocess.PIPE
)
process.communicate(email_text.encode())