# Set up Oauth 2.0

Recently Google and Microsoft changed their authentication method to send e-mails

With both you can either use the OAuth (method 2) authentification or the user/password (method 1), but note that the user/password and not the credentials you use to connect to your mailbox but application password that need to be created.

### Gmail

First make sure to be admin on your Google account, then follow these steps to generate your credentials:

* Go to the [Google cloud console](https://console.cloud.google.com/) dashboard and select a project (or create a new one)

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FIPPSERcDNRkA8zvqGEeX%2Foauth1.png?alt=media&#x26;token=89049b47-804d-4a7e-83e3-9ab4fdde3038" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FTReGKdOBLvJc29dt8Ht3%2Fgmail%20oauth%202%20project%202.png?alt=media&#x26;token=7e6b1450-de6f-4909-a8a5-b83cf8ccd1a9" alt=""><figcaption></figcaption></figure>

* Go to **APIs and services** => **Library**, search for **Gmail API** and enable it

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2F5yjtuDgbD2ZeS6tYmha5%2Foauth3.png?alt=media&#x26;token=5436be2f-23c9-453d-bb7e-55192a25435e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FXrJ5WVHBaLWSKBalrkbk%2Foauth4.png?alt=media&#x26;token=9185ccff-137e-4d2b-8cef-316ebc0c813f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FODr5roswe1yi9lkHh6J6%2Foauth5.png?alt=media&#x26;token=964c9d86-19e1-42c7-a757-90bdd2005f97" alt=""><figcaption></figcaption></figure>

* On the overview page, click the **Create credentials** button (if this is not available, go to the **APIs and services** => **Credentials** menu and select "Create credentials" then "Help me choose". Select the Gmail API).

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FfBkmLdwDIoCLl9SJH8ab%2Foauth6.png?alt=media&#x26;token=e0a9d962-b02d-4dc5-8941-7ba56aae719f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2Fe4nfacNQJoKPh7PMa40m%2Foauth7.png?alt=media&#x26;token=4626c017-c6e3-4c5b-bc26-80636fe4eef5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FIxnwOM9x8CD1lZLyEecJ%2Foauth8.png?alt=media&#x26;token=9c18fbfd-e11b-4f38-8875-d384f4028170" alt=""><figcaption></figcaption></figure>

* You can skip the scope section by clicking the **Save and continue** button

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FDCIlgIr3Mw1K0EMxwjBO%2Foauth9.png?alt=media&#x26;token=e0ad2d29-fa60-46a2-a98b-5726fab72eb4" alt=""><figcaption></figcaption></figure>

* Select **Web application**, then in the **Authorised redirect URIs** section, add the **Redirect URL** that is shown in your AcyMailing configuration page.\
  Note that it may differ if your administration URL has been customised:\
  \- <https://www.example.com/**administrator**/> for Joomla websites\
  \- <https://www.example.com/**wp-admin**/> for WordPress websites

{% hint style="warning" %}
The trailing slash is important, please make sure the redirect URI you enter is exactly the same as shown in your AcyMailing configuration otherwise Google will refuse the connection.
{% endhint %}

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FFklE5LkyEh4wsVZCIybv%2Foauth10.png?alt=media&#x26;token=495a96a9-6666-409b-9db4-86075d86b299" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FstdcPg3uGN4GW2JPVzpH%2Foauth11.png?alt=media&#x26;token=28b8c5a7-4dce-4aef-ad88-2e3f05a31458" alt=""><figcaption></figcaption></figure>

* Go to **OAuth consent screen**, then to **Audience** and make sure your app is "**External**".\
  If you need to switch it from "**Internal**" to "**External**", select the "**In production**" option in the popup.

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FfvwMiQx7fA2FNgvUPu7m%2Foauth12.png?alt=media&#x26;token=cd06fe78-fec5-460e-b9b5-29a470b22eb5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FTUseowDQKl1xRaW2IOrN%2Foauth13.png?alt=media&#x26;token=26c0da0f-e256-4b91-bb23-bf99a9499acd" alt=""><figcaption></figcaption></figure>

* You can then either **publish your app**, or add your email address as a test user. We will use the first method in this example to have permanent credentials. Note that Google can have already set your app in production, in which case you can skip this step.

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FYH07jif0QBqux2CgX4dv%2Fgoogle%20oauth%20publish.png?alt=media&#x26;token=620bdd84-78cc-41c1-a3b0-dc6976496078" alt=""><figcaption></figcaption></figure>

* Go to the **Clients** menu then click the pencil to reveal your credentials

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FDxnvrMKVCdFueavQ9sFo%2Foauth14.png?alt=media&#x26;token=c51fe235-e063-42cb-900c-fd52543ca625" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FK7JTIJHo7oHBReEM4BSw%2Foauth15.png?alt=media&#x26;token=e420168e-a3b9-4275-a116-d8bba721e0b5" alt=""><figcaption></figcaption></figure>

* Copy your **Client ID** and **Client secret** then paste them in your AcyMailing configuration, then configure the connection to your mailbox.

{% tabs %}
{% tab title="SMTP connection (sending emails)" %}
Select the **Google** sending method, then fill in the required information. The username is typically your email address:

* **Username**: your email address
* **Client id**: the Client ID you copied
* **Client secret**: the Client secret key you copied

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FQGyO9SkyQ9bgQcXIMIJV%2Fsmtp%20google.png?alt=media&#x26;token=8e54a35c-c588-4597-b065-bd33586f746e" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="IMAP connection (bounce messages)" %}
The typical configuration for a connection with a Gmail account uses the following values:

* **Bounce email address**: your email address
* **Server**: imap.gmail.com
* **Username**: your email address
* **Client id**: the Client ID you copied
* **Client secret**: the Client secret key you copied

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FbzuYRdTHw5UqeIYvk9fI%2Fbounce%20google.png?alt=media&#x26;token=ccc2f541-748d-4fa0-9e81-0d79655f1278" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

* Once the fields are set, click the Authenticate button then select your Google account

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2F4Xp0afAcUYObFtIoSPte%2Fauthenticate%20google.png?alt=media&#x26;token=06c7e716-03af-4bde-b111-9abc5625250a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FVlIRGp3IiLsRMNUqo8Eq%2Foauth17.png?alt=media&#x26;token=80a97d6c-eba0-4a86-9b40-103262e2c271" alt=""><figcaption></figcaption></figure>

* Google will show a warning because your app hasn't been verified. This is normal, you can click the **Advanced** link at the bottom-left, then **Go to example.com (unsafe)** to be redirected to the consent screen.

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FxCKuYvPFhNGmZHiq7Pvl%2Fgoogle%20consent%20warning.png?alt=media&#x26;token=cc42a7d6-a185-46ed-83db-d3ecf735c508" alt=""><figcaption></figcaption></figure>

* Finally, click the **Continue** button to allow your app to connect to your email address

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FSEhxzv079ef3oXEqC55x%2Foauth19.png?alt=media&#x26;token=b94dd569-a6f3-4b41-a57a-603ebf0405ac" alt=""><figcaption></figcaption></figure>

You should then be redirected to your website and a confirmation should be shown if everything worked correctly:

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FLiL2lN8aR5AsVYdlL5Y2%2Foauth20.png?alt=media&#x26;token=ba0a04e7-ed53-4d2e-8b82-d4a77f116702" alt=""><figcaption></figcaption></figure>

### Outlook

* Sign in to the [Azure portal](https://entra.microsoft.com/#home)
* Search for **App registrations** and select it, then create a **New registration**

![](https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FINYVP78yg1YYM7cVKRC7%2Fsearch.png?alt=media\&token=9088917b-917c-4115-a158-02387c6b00ee)

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2F3UCgIqlx7ebO6yiGEJqX%2Fnew%20reg.png?alt=media&#x26;token=8736295c-d82c-4770-847b-99ca1afd8f8a" alt=""><figcaption></figcaption></figure>

* You can name it how you prefer
* Select **Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)**
* In the **Redirect URI** part, select **Web** then copy and paste the **Redirect URL** shown in your AcyMailing configuration (usually your website's admin URL)
* Click the **Register** button to confirm the creation

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2F9NEiE9lbam0mWci3kOnJ%2Freg%20setup.png?alt=media&#x26;token=0ea8323c-fd5a-4b76-861f-593d3c9d7364" alt=""><figcaption></figcaption></figure>

* Copy the **Application (client) ID**, it is the first part of your credentials so you will need to copy it in your AcyMailing configuration. You can always find it under the **Overview** menu.

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FBi14llkhceO9BfzYojrm%2Fclient%20ID.png?alt=media&#x26;token=c52b84a9-78dc-4a1d-a6fe-ec861f95920a" alt=""><figcaption></figcaption></figure>

* You can now create the second par of your credentials, visit the **Certificates & secrets** menu and click the **New client secret** button

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FILVzlkEEWPhDH6Gvxb1h%2Fsecret.png?alt=media&#x26;token=1673a7b6-3801-4115-85aa-a7dddf1021bc" alt=""><figcaption></figcaption></figure>

* You will be able to choose when these credentials expire (from 6 months to 24 months). Note that you will need to create new credentials here once they expire, and add them into AcyMailing again.
* Click the **Add** button

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FITmhHTTKRXQO5lZ7EIL0%2Ftime%20secret.png?alt=media&#x26;token=27d72ab3-48d9-4d75-928c-61c007fbdbea" alt=""><figcaption></figcaption></figure>

* Copy the value on the next page, this is your Client secret. It is shown only once, if you didn't copy it you can always create a new one.

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FTA3saWzsksYySXWU7CLn%2Fcopy%20secret.png?alt=media&#x26;token=c6f2458b-f574-4629-b3fb-f484848f00ed" alt=""><figcaption></figcaption></figure>

* Your credentials are ready, you can now add them in the AcyMailing configuration:

{% tabs %}
{% tab title="SMTP connection (sending emails)" %}
Before adding your information in AcyMailing, you will need to add some permissions to your Microsoft app:

* Go to **API Permissions**
* Click on **Add a permission**
* Select **Microsoft Graph**
* Select **Delegated permissions**
* Search for **SMTP** and select **SMTP.Send**
* Search for **offline** and select **offline\_access**

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FTXT5ePZsy1WYkJ5KSJEv%2Fsmtp%20grant%20send.png?alt=media&#x26;token=4b50c159-a8ca-4fb7-801a-6064cc3d51a4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FnvUhYGE7t5XgtwKWYVFI%2Fgrant%20offline.png?alt=media&#x26;token=f70edf1f-74a9-4633-afda-cfa1d845e963" alt=""><figcaption></figcaption></figure>

In the AcyMailing configuration, select the **Outlook** sending method then fill in the required information. The username is typically your email address:

* **Username**: your email address
* **Tenant**: In most cases, you can select **Any account type**
* **Client id**: the Application ID you copied
* **Client secret**: the Client secret value you copied

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FJ2v3qHGleQYbuNrY4gwY%2Foutlook9.png?alt=media&#x26;token=7f08952f-08c8-49c2-bec3-cdb65a2926dd" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="IMAP connection (bounce messages)" %}
Before adding your information in AcyMailing, you will need to add some permissions to your Microsoft app:

* Go to **API Permissions**
* Click on **Add a permission**
* Select **Microsoft Graph**
* Select **Delegated permissions**
* Search for **IMAP** and select **IMAP.AccessAsUser.All**
* Search for **offline** and select **offline\_access**

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FCQFeeMXyC9aKcW0OcSpx%2Fpermissions.png?alt=media&#x26;token=54fe8fb1-af10-4a1c-ae5b-e86beb210363" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FKVLfOjjNjeuVZcMfkRx4%2Foffline.png?alt=media&#x26;token=b0964a3f-8ba4-4ace-9ea3-753491a5a8f3" alt="" width="375"><figcaption></figcaption></figure>

You should have the following permissions configured:

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2F3IgYCjz11ryFkbJUP3SH%2Fpermissions.png?alt=media&#x26;token=304c41d2-f652-4eb6-894e-497e594226d9" alt=""><figcaption></figcaption></figure>

If you have a personal email address, you will also need to authorise the IMAP connection by your app in your mailbox settings:

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2F5WlvSlGu5hEqiTdzewGa%2Fimap%20auth.png?alt=media&#x26;token=7dd557d2-d655-4b6d-a06b-993b450a4262" alt=""><figcaption></figcaption></figure>

The typical configuration for a connection with a Microsoft account uses the following values:

* **Bounce email address**: your email address
* **Server**: outlook.office365.com
* **Username**: your email address
* **Tenant**: In most cases, you can select **Any account type**
* **Client id**: the Client ID you copied
* **Client secret**: the Client secret key you copied

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FgFHPs7ijh1asdnSiw6ly%2Foutlook10.png?alt=media&#x26;token=ab481aa1-06fe-4718-8390-f3ed7f1ac5f4" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

* Once the fields are set, click the **Authenticate** button. You will be redirected to the Microsoft account selection.
* On the next page, click the **Accept** button

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2FKcwbRJ5wW1VgEasdi6zC%2Foutlook11.png?alt=media&#x26;token=58bf23ad-5e9a-4ff3-b63a-a23feb013edf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2Fnu0fh1uwZd51EidQ6mCZ%2Foutlook12.png?alt=media&#x26;token=9094929a-e1d8-4169-bbca-d45fb55319a2" alt=""><figcaption></figcaption></figure>

* Once done, you should be redirected to your website with a confirmation message:

<figure><img src="https://963725040-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_D4iy53WFAtKVs3BPA-3566562695%2Fuploads%2F5PjLizyjoIpobrEYrCZR%2Foutlook13.png?alt=media&#x26;token=9617824a-ef60-4817-81ca-406d6d9579f9" alt=""><figcaption></figcaption></figure>
