{"id":18695969,"url":"https://github.com/rahulmoundekar/mail_sending_with_flask_example","last_synced_at":"2025-10-07T19:59:17.497Z","repository":{"id":90410950,"uuid":"258108115","full_name":"rahulmoundekar/mail_sending_with_flask_example","owner":"rahulmoundekar","description":"mail_sending_with_flask_example","archived":false,"fork":false,"pushed_at":"2020-04-24T06:54:23.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-19T00:37:13.855Z","etag":null,"topics":["flask-application","flask-flash","flask-mail","html5","image-manipulation","python-3"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rahulmoundekar.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-23T05:55:04.000Z","updated_at":"2020-04-24T06:54:24.000Z","dependencies_parsed_at":"2023-03-13T17:58:37.060Z","dependency_job_id":null,"html_url":"https://github.com/rahulmoundekar/mail_sending_with_flask_example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rahulmoundekar/mail_sending_with_flask_example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulmoundekar%2Fmail_sending_with_flask_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulmoundekar%2Fmail_sending_with_flask_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulmoundekar%2Fmail_sending_with_flask_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulmoundekar%2Fmail_sending_with_flask_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rahulmoundekar","download_url":"https://codeload.github.com/rahulmoundekar/mail_sending_with_flask_example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulmoundekar%2Fmail_sending_with_flask_example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278838468,"owners_count":26054721,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["flask-application","flask-flash","flask-mail","html5","image-manipulation","python-3"],"created_at":"2024-11-07T11:16:46.035Z","updated_at":"2025-10-07T19:59:17.436Z","avatar_url":"https://github.com/rahulmoundekar.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MAIL Sending with Flask :\n\n#### Project Setup\n\n  - Making the project as :\n     ```\n    mkdir mail_sending_with_flask_example\n    cd mail_sending_with_flask_example\n    ```\n  - Install flask:\n    ```\n    pip install flask\n    ```\n - Integrating Mail and flash Messages\n    ```\n    pip install Flask-Mail\n    pip install flash\n    ```   \n  \n - create settings.py for configuration\n     ```\n     # configuration\n    class Config:\n        DEBUG = True\n    \n        # EMAIL SETTINGS\n        MAIL_SERVER = \"smtp.gmail.com\"\n        MAIL_PORT = 587\n        MAIL_USE_TLS = True\n        MAIL_USE_SSL = False\n        MAIL_USERNAME = 'yourmail@gmail.com'\n        MAIL_PASSWORD = 'app-password'\n    ```\n    \n - create html file inside templates folder\n    * check project directory for index.html and 404.html file for exception handling\n    \n - create curd def in app.py\n    ``` \n    import mimetypes\n    from flask import Flask, render_template, request, redirect, flash\n    from werkzeug.utils import secure_filename\n    from flask_mail import Mail, Message\n    \n    app = Flask(__name__)\n    app.secret_key = 'asrtarstaursdlarsn'\n    app.config.from_object('settings.Config')\n    app.config[\"ALLOWED_IMAGE_EXTENSIONS\"] = [\"JPEG\", \"JPG\", \"PNG\", \"GIF\", \"PDF\"]\n    mail = Mail(app)\n        \n        \n    def allowed_image(filename):\n        if not \".\" in filename:\n            return False\n        ext = filename.rsplit(\".\", 1)[1]\n        if ext.upper() in app.config[\"ALLOWED_IMAGE_EXTENSIONS\"]:\n            return True\n        else:\n            return False\n        \n        \n    @app.route('/', methods=['GET', 'POST'])\n    def compose_attachments():\n        if request.method == 'POST':\n            to = request.form['to']\n            subject = request.form['subject']\n            message = request.form['message']\n            image = request.files[\"file\"]\n    \n            if image.filename == \"\":\n                flash('Please Upload Image file', \"danger\")\n                return redirect(request.url)\n            if allowed_image(image.filename):\n                try:\n                    msg = Message(subject=subject, sender=app.config.get(\"MAIL_USERNAME\"), body=message, recipients=[to])\n    \n                    filename = secure_filename(image.filename)\n                    ctype = mimetypes.MimeTypes().guess_type(filename)[0]\n                    if ctype is None:\n                        ctype = 'application/octet-stream'\n                    f_data = image.read()\n    \n                    msg.attach(filename, ctype, f_data)\n                    mail.send(msg)\n                    flash('Mail Sent Successfully!..check out you inbox', \"success\")\n                except Exception as e:\n                    print(e)\n                    flash('Something went wrong please try again later', \"danger\")\n                    return redirect(request.url)\n            else:\n                flash('That file extension is not allowed', \"danger\")\n                return redirect(request.url)\n        return render_template('index.html')\n        \n        \n    @app.route('/simple', methods=['GET', 'POST'])\n    def compose_mail():\n        if request.method == 'POST':\n            to = request.form['to']\n            subject = request.form['subject']\n            message = request.form['message']\n            try:\n                msg = Message(subject=subject, sender=app.config.get(\"MAIL_USERNAME\"), body=message, recipients=[to])\n                mail.send(msg)\n                flash('Mail Sent Successfully!..check out you inbox', \"success\")\n            except Exception as e:\n                flash('Something went wrong please try again later', \"danger\")\n                return redirect(request.url)\n    \n        return render_template('index.html')\n        \n        \n    @app.errorhandler(404)\n    def page_not_found(e):\n        return render_template(\"404.html\")\n    \n    \n    # run always put in last statement or put after all @app.route\n    if __name__ == '__main__':\n        app.run(host='localhost')\n      ``` \n - In order to run app:\n    ```\n\t  python app.py\n    ```\n\n - run on your browser\n    * Your should run at: http://127.0.0.1:5000/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahulmoundekar%2Fmail_sending_with_flask_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frahulmoundekar%2Fmail_sending_with_flask_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahulmoundekar%2Fmail_sending_with_flask_example/lists"}