Simple mail client
Here is a simple mail client written in Python using the smtplib
and email
libraries:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_email(subject, message, from_addr, to_addr, password):
msg = MIMEMultipart()
msg['From'] = from_addr
msg['To'] = to_addr
msg['Subject'] = subject
body = message
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(from_addr, password)
text = msg.as_string()
server.sendmail(from_addr, to_addr, text)
server.quit()
if __name__ == "__main__":
subject = input("Enter the subject: ")
message = input("Enter the message: ")
from_addr = input("Enter your email address: ")
to_addr = input("Enter the recipient's email address: ")
password = input("Enter your email password: ")
send_email(subject, message, from_addr, to_addr, password)
This script will ask for the subject, message, sender's email address, recipient's email address, and the sender's email password. It will then send an email with the given subject and message to the given recipient.
Please note that you need to allow less secure apps to access your Gmail account. You can do this by going to your Google Account settings and enabling "Less secure app access".
Also, please be aware that storing your email password in plain text is not recommended for security reasons. In a real-world application, you would want to store your password securely, for example, using a secrets manager.
You can also use other email providers like Outlook, Yahoo, etc. Just replace 'smtp.gmail.com' with the SMTP server of your email provider. For example, for Outlook, you would use 'smtp.office365.com'.