Metadata-Version: 1.1
Name: django-mcmailer
Version: 0.2
Summary: A Django app that enables the users to grant access to a Gmail app from Gmail addresses and send emails programmatically on behalf of those addresses.
Home-page: https://gitlab.com/timos222/django_mcmailer
Author: Timotheos Savva
Author-email: timotheos.savva12@gmail.com
License: BSD-3-Clause  # Example license
Description: ==============
        MyCustomMailer
        ==============
        
        MyCustomMailer is a Django app to authenticate Gmails with a simple front-end flow and then used
        programmatically to send emails.
        
        Firstly you will need to create a project in console.cloud.google.com and enable the Gmail API, you can execute
        the step 1 of this quickstart to do this https://developers.google.com/gmail/api/quickstart/python and when you have your
        credentials.json with the following address as a URI "http://localhost:8000/mcmailer/g-auth-endpoint/" you can start
        executing the steps of the following quickstart.
        
        
        Prerequisites
        -------------
        Creating an application on console.cloud.google.com, enabling the Gmail API and getting the credentials.json
        
        * Go to this quickstart by Google https://developers.google.com/gmail/api/quickstart/python and click on the blue
          button that says "Enable the Gmail API"
        * Give your project a name
        * Choose Web Server
        * Add the following address as one of the Authorized redirect URIs "http://localhost:8000/mcmailer/g-auth-endpoint/"
        * Click "Create"
        * Click "DOWNLOAD CLIENT CONFIGURATION"
        * Finally click the blue link that says 'API Console' at the bottom right of the pop-up to open the new project in
          the console.
        
        This is it, now you've created an application in the cloud, enabled the Gmail API and added as Authorized redirect URI the
        localhost link that this package will use. No you can grant 'gmail.send' access to your app from any Gmail address
        and send emails on behalf of that address through your Django-app.
        
        Production
        ----------
        If you want your users to be able to grant access to your application in a production environment and implement this
        to your Django application flow so you can send emails programmatically on behalf of them, then you need to add your
        live production URL (e.g. "https://example.com/mcmailer/g-auth-endpoint/") to the Authorized redirect URIs. To do this
        you need to console.developers.google.com, select the project you've created earlier, click credentials from the left
        menu, under 'OAuth 2.0 Client IDs' there is you will see the credentials you created earlier, click on the pencil to edit
        the credentials, add your production URI click save, download the updated credentials.json and replace it in your project.
        
        Quick start
        -----------
        
        1. Add "mcmailer" to your INSTALLED_APPS setting like this::
        
            INSTALLED_APPS = [
                ...
                'mcmailer',
            ]
        
        2. Include the polls URLconf in your project urls.py like this::
        
            path('mcmailer/', include('mcmailer.urls')),
        
        3. Run ``python manage.py migrate`` to create the mcmailer models.
        
        4. In the settings.py you must declare the following four settings::
        
            JSON_PATH = "/my/path/to/client_secret.json"
            LOCAL_HOST = True
            LOCAL_HOST_REDIRECT_URI = "http://localhost:8000/mcmailer/g-auth-endpoint/"
            PRODUCTION_REDIRECT_URI = "https://example.com/mcmailer/g-auth-endpoint/"
        
        5. The JSON_PATH setting is the path that the 'credentials.json' will be located.The credentials.json is the file that Gmail API will give you when you create a project in the console and enable the Gmail API. Go to https://developers.google.com/gmail/api/quickstart/python and follow the step 1 to create a project and enable the Gmail API in the console.cloud.google.com, when you finish, download the credentials.json put it somewhere in your project and write the path of it in the JSON_PATH variable in your settings.py.
        
        6. The LOCAL_HOST settings is a boolean variable that should be True if you are on localhost and False when you are in production.
        
        7. The LOCAL_HOST_REDIRECT_URI setting is one (or the only one) of the Authorized redirect URIs that you will put in your credentials in the console.cloud.google.com. This URI will be used if the LOCAL_HOST is equal to True. The URI must point to a specific view so just change the part (if needed) before the /mcmailer/g-auth-endpoint/. Example: LOCAL_HOST_REDIRECT_URI = "http://localhost:8000/mcmailer/g-auth-endpoint/"
        
        8. The PRODUCTION_REDIRECT_URI setting is one (or the only one) of the Authorized redirect URIs that you will put in your credentials in the console.cloud.google.com. This URI will be used if the LOCAL_HOST is equal to False. The URI must point to a specific view so just change the part (if needed) before the /mcmailer/g-auth-endpoint/. Example: LOCAL_HOST_REDIRECT_URI = "https://example.com/mcmailer/g-auth-endpoint/"
            * If your app doesn't need to authenticate new users on production and you only need to authenticate your own Gmail to sent emails programmatically then you can just authenticate your Gmail locally once and leave the LOCAL_HOST variable to False and don't declare the PRODUCTION_REDIRECT_URI variable in your settings.py.
        
        9. Start the development server and visit http://127.0.0.1:8000/mcmailer/connect/
           enter the email you want to to grand access to your application and click submit.
        
        10. Now that you have successfully granted access to your application from at least one Gmail, you can send emails from
        that email using send_mc_email() function of the package::
        
                from mcmailer.utils.sendgmail import send_mc_email, load_credentials
        
                authorized_gmail_address = 'someaddress@gmail.com'
                success, credentials = load_credentials(authorized_gmail_address)
                send_mc_email(
                    credentials,
                    from_address=authorized_gmail_address,
                    to_addresses=[
                        'toaddress2@gmail.com',
                        'toaddress3@gmail.com',
                        'toaddress4@gmail.com'
                    ],
                    from_official_name='MY OFFICIAL NAME',
                    subject='My Subject',
                    msg_plain='My Plain Email Body',
                    msg_html='My HTML Email Body'
                )
        
        
Platform: UNKNOWN
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.1
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
