1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart
def send_email(): print("Preparing to send email...") sender_email = 'your_email@example.com' receiver_email = 'receiver_email@example.com' password = 'your_email_password'
smtp_server = 'smtp.yourmail.com' smtp_port = 587
subject = 'subject' body = 'body'
message = MIMEMultipart() message['From'] = sender_email message['To'] = receiver_email message['Subject'] = subject message.attach(MIMEText(body, 'plain'))
try: print("Connecting to SMTP server...") with smtplib.SMTP(smtp_server, smtp_port) as server: server.starttls() print("Logging in to SMTP server...") server.login(sender_email, password) print("Sending email...") server.sendmail(sender_email, receiver_email, message.as_string()) print("Email sent successfully.") except Exception as e: print(f"Email sent failed: {e}")
def main(): send_mail()
|