71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""
|
|
SMTP Test Email Sender for Yandex Cloud Postbox
|
|
|
|
Скрипт для отправки тестового email через Yandex Cloud Postbox SMTP сервер.
|
|
Используется для проверки корректности настроек SMTP аутентификации.
|
|
|
|
Примеры использования:
|
|
python3 smtp-send-test-email.py --login "your-login" --password "smtp-password" --to "recipient@example.com"
|
|
"""
|
|
|
|
import smtplib
|
|
import argparse
|
|
import sys
|
|
from email.message import EmailMessage
|
|
|
|
|
|
def send_test_email(login, password, to_email):
|
|
"""Отправляет тестовое email через Yandex Cloud Postbox SMTP"""
|
|
|
|
# initialize connection to our email server
|
|
smtp = smtplib.SMTP("postbox.cloud.yandex.net", port="587")
|
|
|
|
smtp.set_debuglevel(2)
|
|
|
|
smtp.ehlo() # send the extended hello to our server
|
|
smtp.starttls() # tell server we want to communicate with TLS encryption
|
|
|
|
smtp.login(login, password) # login to our email server
|
|
|
|
message = EmailMessage()
|
|
message.set_content("Hello, world! This is a test email from Yandex Cloud Postbox.")
|
|
message.add_header("From", login)
|
|
message.add_header("To", to_email)
|
|
message.add_header("Subject", "Test Email from Yandex Cloud Postbox")
|
|
|
|
# send our email message
|
|
smtp.send_message(message)
|
|
|
|
smtp.quit() # finally, don't forget to close the connection
|
|
|
|
print(f"Test email successfully sent to {to_email}")
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Send a test email via Yandex Cloud Postbox SMTP server."
|
|
)
|
|
parser.add_argument(
|
|
"--login", required=True, help="SMTP login (usually your email address)"
|
|
)
|
|
parser.add_argument(
|
|
"--password",
|
|
required=True,
|
|
help="SMTP password (generated using smtp-convert-secret-key-to-password.py)",
|
|
)
|
|
parser.add_argument("--to", required=True, help="Recipient email address")
|
|
|
|
args = parser.parse_args()
|
|
|
|
try:
|
|
send_test_email(args.login, args.password, args.to)
|
|
except Exception as e:
|
|
print(f"Error sending email: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|