PROGRAM - 10-Aim and Alg
PROGRAM - 10-Aim and Alg
Aim
Algorithm
ii) MIME Multipart and MIME text from email mime multipart for creating email content
Step6: Try to send the mail by establishing connection to the SMTP server.
Step7: Print an error message if any exception occur during the sending process.
import smtplib
recipient_email = "[email protected]"
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = recipient_email
message.attach(MIMEText(body, "plain"))
smtp_server = "smtp.gmail.com"
smtp_port = 587
try:
server.starttls()
server.login(sender_email, sender_password)
text = message.as_string()
except Exception as e:
print("Error:", e)
finally:
server.quit()
output :
C:\Users\TEMP.CTIT.119\PycharmProjects\pythonProject\venv\bin\python.exe
C:/Users/TEMP.CTIT.119/PycharmProjects/pythonProject/smt.py
Result
Thus the program for sending mail using SMTP has been executed and verified successfully.