diff --git a/gmail_birthday_sender/README.md b/gmail_birthday_sender/README.md new file mode 100644 index 000000000..16f15e4fe --- /dev/null +++ b/gmail_birthday_sender/README.md @@ -0,0 +1,98 @@ +# Gmail Birthday Sender + +This script automatically sends birthday wishes via Gmail. +You just need to enter your information at beginning. + +## Requirements + +- Python 3 + +## Instructions + +1. Create google account +2. Turn on [2-Step Verification](https://support.google.com/accounts/answer/185839) +3. Create [an application password](https://support.google.com/accounts/answer/185833#zippy=%2Cremove-app-passwords) + +### Enter your information in `main.py` + +- Enter your gmail account, your name and application password + +```py +your_name = "your_real_name" +your_email = "your_account@gmail.com" +password = "your_gmailpassword" +``` + +- Enter recipient's information here + +```py + # Change John to recipient's name + "John": { + # Change john@example.com into real recipient's email + "email": "john@example.com", + # Change Month and Day of a birthday + "birthday": datetime.date(1995, 12, 31), +``` + +(Example) +Name: John +Email: john@example.com, +Year, Month and Day of a birthday: 1995, 12, 31 + +- Enter absolute path to a attachement file if you want + +```py + "attachment": "/path/to/john_card.pdf" + }, +``` + +If you don't need, write `None` instead + +```py + "attachment": None +``` + +- If you want to change the subject and body of email, modify below string + +```py + subject = f"Happy birthday {name}!" + body = f"""Dear {name}, + + Wishing you a very happy birthday filled with love, laughter, and joy! + May all your dreams and aspirations come true. + Looking forward to seeing you soon! Have a fantastic birthday! + + Best wishes, {self.your_name}""" +``` + +### Run the script + +After you're done installing Python and pip, run the following command from your terminal to install the requirements from the same folder (directory) of the project. + +```bash +pip install -r requirements.txt +``` + +After satisfying all the requirements for the project, Open the terminal in the project folder and run + +```bash +python dictionary.py +``` + +or + +```bash +python3 dictionary.py +``` + +> [!IMPORTANT] +> Script should be run anytime to send birthday wishes automatically + +## Output + +![Example of output](example_of_birthday_sender.png) + +## Disclaimers, if any + +> [!WARNING] +> This script lacks strong security for your email diff --git a/gmail_birthday_sender/example_of_birthday_sender.png b/gmail_birthday_sender/example_of_birthday_sender.png new file mode 100644 index 000000000..32d6812d4 Binary files /dev/null and b/gmail_birthday_sender/example_of_birthday_sender.png differ diff --git a/gmail_birthday_sender/main.py b/gmail_birthday_sender/main.py new file mode 100644 index 000000000..796b25d0b --- /dev/null +++ b/gmail_birthday_sender/main.py @@ -0,0 +1,100 @@ +import yagmail +import datetime +import schedule +import time +import os +from typing import Optional + +# Input your information by chnaging string part from here--------------------- +# used for email body (e.g. sincerely ) +your_name = "your_real_name" +your_email = "your_account@gmail.com" +# Your application password can be used only after 2-step verification +password = "your_gmailpassword" + +# Enter recipient information below + +birthday_list = { + # Change John to recipient's name + "John": { + # Change john@example.com into real recipient's email + "email": "john@example.com", + # Change Year, Month and Day of a birthday + "birthday": datetime.date(1995, 12, 31), + # Enter an absolute path to attachement file + "attachment": "/path/to/john_card.pdf", + }, + "Jane": { + "email": "jane@example.com", + "birthday": datetime.date(2001, 8, 22), + "attachment": None, # 添付ファイルなし + }, # Add other recipient from a below line +} +# ----------------------------------------------------------------------------- + + +class BirthdaySender: + """This automatically sends birthday wishes via Gmail.""" + + def __init__(self, your_name, your_email, password) -> None: + self.your_name = your_name + self.sender_email = your_email + self.birthday_list = birthday_list + # for safer password storage + yagmail.register(your_email, password) + self.yag = yagmail.SMTP(your_email) + + def send_email( + self, name: str, to_email: str, attachment_path: Optional[str] = None + ) -> None: + """Include attachement to email file if it is needed""" + + # If you want to change the content, modify below---------------------- + subject = f"Happy birthday {name}!" + body = f"""Dear {name}, + + Wishing you a very happy birthday filled with love, laughter, and joy! + May all your dreams and aspirations come true. + Looking forward to seeing you soon! Have a fantastic birthday! + + Best wishes, {self.your_name}""" + # --------------------------------------------------------------------- + + email_params = {"to": to_email, "subject": subject, "contents": body} + + if attachment_path and os.path.exists(attachment_path): + email_params["attachments"] = attachment_path + print(f"{attachment_path} was included") + + try: + self.yag.send(**email_params) + print(f"Sent to {name}") + except Exception as e: + print(f"Failed to send email to {name}, Error: {e}") + + def send_email_if_birthday(self) -> None: + """Call send_email if today is birthday""" + today = datetime.date.today() + + for name, info in self.birthday_list.items(): + birthday = info["birthday"] + if today.month == birthday.month and today.day == birthday.day: + return self.send_email(name, info["email"], info["attachment"]) + + def run(self): + return self.send_email_if_birthday() + + +if __name__ == "__main__": + birthday_sender = BirthdaySender(your_name, your_email, password) + + schedule.every().day.at("07:00").do(birthday_sender.run) + + try: + while True: + schedule.run_pending() + time.sleep(1) + except KeyboardInterrupt: + print("Birthday sending stopped") + except Exception as e: + print(f"An error: {e}") diff --git a/gmail_birthday_sender/requirements.txt b/gmail_birthday_sender/requirements.txt new file mode 100644 index 000000000..79d025dc4 --- /dev/null +++ b/gmail_birthday_sender/requirements.txt @@ -0,0 +1,21 @@ +cachetools==5.5.0 +certifi==2024.8.30 +charset-normalizer==3.3.2 +cssselect==1.2.0 +cssutils==2.11.1 +flake8==7.1.1 +idna==3.8 +jaraco.classes==3.4.0 +jaraco.context==6.0.1 +jaraco.functools==4.0.2 +keyring==25.4.1 +lxml==5.3.0 +mccabe==0.7.0 +more-itertools==10.5.0 +premailer==3.10.0 +pycodestyle==2.12.1 +pyflakes==3.2.0 +requests==2.32.3 +schedule==1.2.2 +urllib3==2.2.2 +yagmail==0.15.293