smtp_server = "smtp.company.com"
smtp_port = 587 # Use 587 for STARTTLS
sender_email = "your-email@company.com"
recipient_email = "recipient@example.com"
subject = "Test Email with TLS"
body = "This email was sent with TLS encryption."
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = recipient_email
message["Subject"] = subject
message.attach(MIMEText(body, "plain"))
try:
with smtplib.SMTP(smtp_server, smtp_port) as server:
# Enable TLS encryption
server.starttls(context=ssl.create_default_context())
# Send email (no login required for relay)
server.sendmail(sender_email, recipient_email, message.as_string())
print("Email sent successfully with TLS!")
except Exception as e:
print(f"Error sending email: {e}")