Skip to content

Commit f84b69b

Browse files
committed
created a python script with a GUI which sends an automated mail to the mentioned mail ID.
1 parent 0fa47cd commit f84b69b

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

birthday-gmail-script/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Generate an App Password:
2+
3+
1. Go to Google Account Security Settings.
4+
5+
2. Under "Signing in to Google," find App passwords and create one for this script (you’ll need to have 2-step verification enabled on your account).
6+
7+
3. Use this app password in the script instead of your Gmail account password.
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import smtplib
2+
from email.mime.text import MIMEText
3+
from email.mime.multipart import MIMEMultipart
4+
import tkinter as tk
5+
from tkinter import messagebox
6+
7+
# Function to send email
8+
def send_birthday_wish(sender_email, app_password, receiver_email, birthday_message):
9+
try:
10+
# Create the email
11+
msg = MIMEMultipart()
12+
msg['From'] = sender_email
13+
msg['To'] = receiver_email
14+
msg['Subject'] = 'Happy Birthday! 🎉'
15+
16+
# Add the birthday message to the email
17+
msg.attach(MIMEText(birthday_message, 'plain'))
18+
19+
# Connect to Gmail's SMTP server
20+
server = smtplib.SMTP('smtp.gmail.com', 587)
21+
server.starttls() # Enable TLS encryption
22+
server.login(sender_email, app_password)
23+
24+
# Send the email
25+
text = msg.as_string()
26+
server.sendmail(sender_email, receiver_email, text)
27+
28+
# Disconnect from the server
29+
server.quit()
30+
31+
messagebox.showinfo("Success", "Birthday wish sent successfully!")
32+
33+
except Exception as e:
34+
messagebox.showerror("Error", f"Failed to send email. Error: {e}")
35+
36+
# Function to get input from the user and send the email
37+
def send_email():
38+
sender_email = entry_sender_email.get()
39+
app_password = entry_app_password.get()
40+
receiver_email = entry_receiver_email.get()
41+
birthday_message = text_birthday_message.get("1.0", tk.END) # Get text from Text widget
42+
43+
if not sender_email or not app_password or not receiver_email or not birthday_message.strip():
44+
messagebox.showwarning("Input Error", "All fields are required!")
45+
return
46+
47+
send_birthday_wish(sender_email, app_password, receiver_email, birthday_message)
48+
49+
# GUI Setup
50+
app = tk.Tk()
51+
app.title("Birthday Wisher with Gmail")
52+
app.geometry("400x400")
53+
54+
# Gmail sender email label and entry
55+
label_sender_email = tk.Label(app, text="Your Gmail:")
56+
label_sender_email.pack(pady=5)
57+
entry_sender_email = tk.Entry(app, width=40)
58+
entry_sender_email.pack(pady=5)
59+
60+
# App password label and entry
61+
label_app_password = tk.Label(app, text="App Password:")
62+
label_app_password.pack(pady=5)
63+
entry_app_password = tk.Entry(app, show='*', width=40)
64+
entry_app_password.pack(pady=5)
65+
66+
# Recipient email label and entry
67+
label_receiver_email = tk.Label(app, text="Recipient's Email:")
68+
label_receiver_email.pack(pady=5)
69+
entry_receiver_email = tk.Entry(app, width=40)
70+
entry_receiver_email.pack(pady=5)
71+
72+
# Birthday message label and text entry
73+
label_birthday_message = tk.Label(app, text="Birthday Wishes:")
74+
label_birthday_message.pack(pady=5)
75+
text_birthday_message = tk.Text(app, height=5, width=40)
76+
text_birthday_message.pack(pady=5)
77+
78+
# Send button
79+
send_button = tk.Button(app, text="Send Birthday Wish", command=send_email)
80+
send_button.pack(pady=10)
81+
82+
# Run the application
83+
app.mainloop()

0 commit comments

Comments
 (0)