Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-61921

Support XOAUTH2 for outgoing/incoming mail

XMLWordPrintable

    • MOODLE_310_STABLE, MOODLE_33_STABLE, MOODLE_34_STABLE, MOODLE_35_STABLE, MOODLE_39_STABLE
    • MOODLE_401_STABLE
    • MDL-61921-master
    • Hide

      Initial setup - OAuth

      1. Follow OAuth 2 Google service to get the Client Id and Client secret.
      2. Enable Gmail API in the Google Developer console.
      3. Login as admin.
      4. Navigate to Site Administrator > Server >  OAuth 2 services
      5. Create a new Google service called: Gmail - OAUTH2.
      6. Set the Client id and Client secret.
      7. Set the Scopes included in a login request value to: "openid profile email https://mail.google.com" (Without the quote).
      8. Set the Scopes included in a login request for offline access value to: "openid profile email https://mail.google.com" (Without the quote).
      9. Save changes.
      10. Click Connect to a system account and finish it.

      Initial setup - SMTP

      1. Navigate to Site Administrator > Server > Email > Outgoing Mail Configuration.
      2. Set the following value:
        • SMTP hosts: smtp.gmail.com:587
        • SMTP Security: TLS
        • SMTP Auth Type: XOAUTH2
        • OAuth 2 Service: Gmail - OAUTH2
        • SMTP username: The username that was used to connect to Google Developer Console.
      3. Save changes

      Outgoing mail testing

      1. Navigate to Site Administrator > Server > Email > Outgoing Mail Configuration -> Test outgoing mail configuration
      2. To email address: Your email address to receive the test email.
      3. Additional subject: Test email using XOAUTH2
      4. Press Send a test message.
      5. Verify that you will see:  This site has successfully sent a test message to the mail server.
      6. Open your email inbox.
      7. Verify that you will see an email with:
        • Title: [Your site name]: test message. Test email using XOAUTH2
        • Content: This is a test message to confirm that you have successfully configured your site's outgoing mail.

      Initial setup - IMAP

      1. Navigate to Site Administrator > Server > Email > Incoming Mail Configuration.
      2. Set the following value:
        1. Enable incoming mail processing: Checked
        2. Mailbox name: the name before @ sign of your email address (Ex: Your email is abc@gmail.com, the Mailbox name will be: abc)
        3. Email domain: the name after @ sign of your email address. In this case, it will be: gmail.com
        4. Incoming Mail Server: imap.gmail.com
        5. OAuth 2 Service: Gmail - OAUTH2
        6. Username: The username that was used to connect to the Google Developer Console.
      3. Save changes.
      4. Navigate to Site Administrator > Server > Email > Message handlers.
      5. Enable the Email to Private files.

      Incoming mail testing

      1. Create a new tab on your browser called Tab 1.
      2. On Tab 1, click on the User Profile menu > Profile.
      3. Observe the Email address of the admin user. (Example: xyz@gmail.com)
      4. Create a new tab on your browser called Tab 2.
      5. On Tab 2, open the webmail of the Admin's email (Example: https://mail.google.com)
      6. On Tab 1, click on the User Profile menu > Private files.
      7. Verify that you will see: You can also e-mail files as attachments straight to your private files space. 
      8. Copy the email address.
      9. On Tab 2, compose a new email with the following value:
        1. To: The copied email address.
        2. Subject: Test attachment
        3. Content: Attached
        4. Attachment: Attach an image on your machine.
      10. Send the email.
      11. Run command: php admin/cli/scheduled_task.php --execute='tool_messageinbound\task\pickup_task'
      12. On Tab 1, click on the User Profile menu > Private files.
      13. Verify that you will see the image that you have sent via email.

       

      Show
      Initial setup - OAuth Follow OAuth 2 Google service to get the Client Id and Client secret . Enable Gmail API in the Google Developer console. Login as admin. Navigate to Site Administrator > Server >  OAuth 2 services Create a new Google service called: Gmail - OAUTH2 . Set the Client id and Client secret . Set the Scopes included in a login request value to: "openid profile email https://mail.google.com " ( Without the quote ). Set the Scopes included in a login request for offline access value to: "openid profile email https://mail.google.com " ( Without the quote ). Save changes. Click Connect to a system account and finish it. Initial setup - SMTP Navigate to Site Administrator > Server > Email > Outgoing Mail Configuration. Set the following value: SMTP hosts: smtp.gmail.com:587 SMTP Security: TLS SMTP Auth Type: XOAUTH2 OAuth 2 Service: Gmail - OAUTH2 SMTP username: The username that was used to connect to Google Developer Console. Save changes Outgoing mail testing Navigate to Site Administrator > Server > Email > Outgoing Mail Configuration -> Test outgoing mail configuration To email address: Your email address to receive the test email. Additional subject: Test email using XOAUTH2 Press Send a test message. Verify that you will see:  This site has successfully sent a test message to the mail server. Open your email inbox. Verify that you will see an email with: Title : [Your site name] : test message. Test email using XOAUTH2 Content : This is a test message to confirm that you have successfully configured your site's outgoing mail. Initial setup - IMAP Navigate to Site Administrator > Server > Email > Incoming Mail Configuration. Set the following value: Enable incoming mail processing: Checked Mailbox name: the name before @ sign of your email address (Ex: Your email is abc@gmail.com, the Mailbox name will be: abc) Email domain: the name after @ sign of your email address. In this case, it will be: gmail.com Incoming Mail Server: imap.gmail.com OAuth 2 Service: Gmail - OAUTH2 Username: The username that was used to connect to the Google Developer Console. Save changes. Navigate to Site Administrator > Server > Email > Message handlers. Enable the Email to Private files. Incoming mail testing Create a new tab on your browser called Tab 1 . On Tab 1, click on the User Profile menu > Profile. Observe the Email address of the admin user. (Example: xyz@gmail.com) Create a new tab on your browser called Tab 2 . On Tab 2 , open the webmail of the Admin's email (Example: https://mail.google.com) On Tab 1 , click on the User Profile menu > Private files. Verify that you will see: You can also e-mail files as attachments straight to your private files space.  Copy the email address. On Tab 2 , compose a new email with the following value: To: The copied email address. Subject: Test attachment Content: Attached Attachment: Attach an image on your machine. Send the email. Run command: php admin/cli/scheduled_task.php --execute='tool_messageinbound\task\pickup_task' On Tab 1, click on the User Profile menu > Private files. Verify that you will see the image that you have sent via email.  
    • 6
    • Team Hedgehog 4.1 sprint 0.4B, Team Hedgehog 4.1 sprint 0 rev

      When using GMail Services for outgoing and/or incoming messages in Moodle, it is required to lower the security of the GMail account: https://support.google.com/mail/answer/78754.

      It would be better to natively implement the support for the XOAUTH2, as required e.g. by GMail with the IMAP AUTHENTICATE and SMTP AUTH commands.

      In the Community, iarenaza has already provided more than a working proof for the incoming mails:

        1. 1_MDL-61921.png
          1_MDL-61921.png
          32 kB
        2. 2_MDL-61921.png
          2_MDL-61921.png
          28 kB
        3. 3_MDL-61921.png
          3_MDL-61921.png
          36 kB
        4. 4_MDL-61921.png
          4_MDL-61921.png
          272 kB
        5. 5_MDL-61921.png
          5_MDL-61921.png
          88 kB
        6. Screen Shot 2022-10-11 at 5.28.10 pm.png
          Screen Shot 2022-10-11 at 5.28.10 pm.png
          37 kB
        7. Screen Shot 2022-10-11 at 5.52.48 pm.png
          Screen Shot 2022-10-11 at 5.52.48 pm.png
          50 kB
        8. wip_34-xoauth2.patch
          6 kB

            huongn@moodle.com Huong Nguyen
            matteo Matteo Scaramuccia
            David Woloszyn David Woloszyn
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            John Edward Pedregosa John Edward Pedregosa
            Votes:
            14 Vote for this issue
            Watchers:
            26 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 days, 7 hours, 6 minutes
                4d 7h 6m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.