Give a python code for send email
- User
Give a python code for send email
Assistant
Sure, here's an example Python code that uses the built-in
smtplibandemail.mimemodules to send an email:import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart # Set up the email message msg = MIMEMultipart() msg['From'] = 'your_email@example.com' msg['To'] = 'recipient_email@example.com' msg['Subject'] = 'Test email from Python' # Add the email body body = 'This is a test email sent from Python.' msg.attach(MIMEText(body, 'plain')) # Set up the SMTP server smtp_server = 'smtp.example.com' smtp_port = 587 smtp_username = 'your_email@example.com' smtp_password = 'your_email_password' # Send the email server = smtplib.SMTP(smtp_server, smtp_port) server.starttls() server.login(smtp_username, smtp_password) text = msg.as_string() server.sendmail(msg['From'], msg['To'], text) server.quit() print('Email sent!')Make sure to replace the placeholders (e.g.
your_email@example.com,smtp.example.com, etc.) with your actual email address, SMTP server, and other relevant information.