{"library":"aiosmtplib","code":"import asyncio\nimport os\nfrom email.message import EmailMessage\nfrom aiosmtplib import send\n\nasync def main():\n    sender_email = os.environ.get('SMTP_SENDER_EMAIL', 'sender@example.com')\n    recipient_email = os.environ.get('SMTP_RECIPIENT_EMAIL', 'recipient@example.com')\n    smtp_host = os.environ.get('SMTP_HOST', 'localhost')\n    smtp_port = int(os.environ.get('SMTP_PORT', 25))\n    smtp_password = os.environ.get('SMTP_PASSWORD', None)\n\n    message = EmailMessage()\n    message['From'] = sender_email\n    message['To'] = recipient_email\n    message['Subject'] = 'Hello from aiosmtplib!'\n    message.set_content('This is a test email sent using aiosmtplib.')\n\n    try:\n        await send(\n            message,\n            hostname=smtp_host,\n            port=smtp_port,\n            username=sender_email if smtp_password else None,\n            password=smtp_password,\n            start_tls=True if smtp_port == 587 else False, # Use STARTTLS for common submission port\n            use_tls=True if smtp_port == 465 else False # Use direct TLS for common SMTPS port\n        )\n        print(f\"Email sent successfully from {sender_email} to {recipient_email}\")\n    except Exception as e:\n        print(f\"Failed to send email: {e}\")\n\nif __name__ == '__main__':\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates sending an email using the high-level `aiosmtplib.send` coroutine. It uses environment variables for configuration and handles common TLS/STARTTLS scenarios. For more complex interactions or persistent connections, the `SMTP` client class with an `async with` context manager is recommended.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}