SMTP on Serv00 with Python script
# SMTP on Serv00 Python script
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import logging

# Configure logging
logging.basicConfig(level=logging.DEBUG)

# SMTP server configuration
smtp_server = 'mail3.serv00.com'
smtp_port = 587
username = 'your_username'  # Replace with your username
password = 'your_password'  # Replace with your password

# Create email content
msg = MIMEMultipart()
msg['From'] = '[email protected]'  # Replace with sender's email address
msg['To'] = '[email protected]'  # Replace with recipient's email address
msg['Subject'] = 'Test Email'
body = 'This is a test email.'
msg.attach(MIMEText(body, 'plain'))

try:
    server = smtplib.SMTP(smtp_server, smtp_port)
    server.set_debuglevel(1)  # Enable debug output
    server.starttls()  # Enable TLS encryption

    # Log in to SMTP server
    server.login(username, password)

    # Send email
    text = msg.as_string()
    server.sendmail(msg['From'], msg['To'], text)
    print("Email sent successfully")

except Exception as e:
    print(f"Failed to send email: {e}")

finally:
    # Disconnect from the server
    server.quit()

Explanation:

  • SMTP server configuration: Replace smtp_server, username, and password with your SMTP server address, username, and password.
  • Email content: Replace msg['From'] and msg['To'] with actual sender and recipient email addresses.
  • Exception handling: Uses a try-except-finally block to handle potential exceptions, ensuring graceful closure of the SMTP connection even if sending the email fails.

This Python script connects to the specified SMTP server, sends a test email using TLS encryption, and handles exceptions that may occur during the process.

No Comments

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous
Next