{"id":21492136,"url":"https://github.com/colddsam/smtpapi","last_synced_at":"2025-03-17T11:23:23.465Z","repository":{"id":218270634,"uuid":"746007273","full_name":"colddsam/smtpAPI","owner":"colddsam","description":"﻿ smtpAPI Python program sends emails using SMTP protocol. It integrates with FastAPI to allow sending emails with custom content via a REST API.","archived":false,"fork":false,"pushed_at":"2024-01-24T04:38:12.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T20:51:57.415Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/colddsam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2024-01-20T19:58:57.000Z","updated_at":"2024-01-20T20:24:35.000Z","dependencies_parsed_at":"2024-01-24T05:31:27.406Z","dependency_job_id":null,"html_url":"https://github.com/colddsam/smtpAPI","commit_stats":null,"previous_names":["colddsam/smtpapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colddsam%2FsmtpAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colddsam%2FsmtpAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colddsam%2FsmtpAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colddsam%2FsmtpAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/colddsam","download_url":"https://codeload.github.com/colddsam/smtpAPI/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244022636,"owners_count":20385133,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-23T15:22:51.499Z","updated_at":"2025-03-17T11:23:23.395Z","avatar_url":"https://github.com/colddsam.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### smtpAPI Python Example\nThe provided code is an example of how to use the SMTP API in Python to send emails.\n\n#### smtpOperation.py:\nThe `smtpOperation.py` contains the code related to sending emails:\n\n1. **Importing Libraries:**\n   - The required libraries are imported:\n     - `dotenv`: For loading environment variables.\n     - `os`: For accessing environment variables.\n     - `smtplib`: For sending emails.\n     - `email.mime.text`: For creating plain text email messages.\n     - `email.mime.multipart`: For creating multipart email messages.\n\n2. **Loading Environment Variables:**\n   - The `load_dotenv()` function is used to load environment variables from a `.env` file.\n   - This file should contain the following variables:\n     - `EMAIL_ID`: Your SMTP username (email address).\n     - `PASSWORD`: Your SMTP password.\n     - `DEFAULT_USER`: The default recipient email address.\n\n3. **`send_mail()` Function:**\n   - This function takes one optional argument, `text`, which defaults to \"choco\".\n   - It builds a multipart email message with the following components:\n     - `From`: The sender's email address (specified by `smtp_username`).\n     - `To`: The recipient's email address (specified by `receiver_email`).\n     - `Subject`: The subject of the email (\"Gift Choose\").\n     - `text`: The body of the email, which is a plain text message containing the value of the `text` argument.\n\n4. **Sending the Email:**\n   - The email is sent using the SMTP protocol.\n   - It connects to the SMTP server (`smtp.gmail.com`) on port 587.\n   - It logs in using the credentials specified in the environment variables.\n   - It sends the email using the `sendmail()` method.\n   - If the email is sent successfully, a confirmation message is printed.\n   - If there is an error while sending the email, an error message is printed.\n\n#### main.py:\nThe `main.py` contains the FastAPI application:\n\n1. **Importing Libraries:**\n   - `FastAPI`: For creating the FastAPI application.\n   - `CORSMiddleware`: For enabling CORS (Cross-Origin Resource Sharing) in the application.\n   - `smtpOperation`: The module containing the `send_mail()` function.\n\n2. **FastAPI Application:**\n   - An instance of the FastAPI application is created.\n   - The `add_middleware()` method is used to add the `CORSMiddleware` middleware to the application. This allows the API to accept requests from any origin.\n\n3. **Root Page:**\n   - The root page (`/`) is defined. When a GET request is made to this endpoint, it returns a simple message indicating that the project is for checking TensorFlow operations.\n\n4. **`predict()` Function:**\n   - The `/gift/` endpoint is defined to accept a GET request with a `gift` query parameter.\n   - The `gift` query parameter is required and represents the gift chosen by a person.\n   - The function tries to send an email using the `send_mail()` function, passing the value of the `gift` parameter as the email body.\n   - If the email is sent successfully, it returns \"successful\"; otherwise, it returns \"unsuccessful.\"\n\n\nTo use this code, you need to follow these steps:\n\n1. Create a `.env` file and populate it with the necessary environment variables:\n   ```\n   EMAIL_ID=your_smtp_username\n   PASSWORD=your_smtp_password\n   DEFAULT_USER=default_recipient_email\n   ```\n\n2. Run the `smtpOperation.py` script to ensure that the email sending functionality is working properly.\n\n3. Run the `main.py` script to start the FastAPI application.\n\n4. You can now visit the root page at `http://localhost:8000/` to see the project description.\n\n5. To test the email sending functionality, visit `http://localhost:8000/gift/?gift=YOUR_GIFT_CHOICE`. Replace `YOUR_GIFT_CHOICE` with the gift you want to send in the email.\n\n6. If the email is sent successfully, you should see a \"successful\" response. Otherwise, you will see an \"unsuccessful\" response.\n\n7. Check your email inbox to verify that you have received the email with the gift choice","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolddsam%2Fsmtpapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcolddsam%2Fsmtpapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolddsam%2Fsmtpapi/lists"}