Mail Service
Configuration settings are available for the Mail Service application to work. These settings can basically be grouped under 2 headings.
Oauth2.0 Login Application and Parameters
In order to work with Oauth2.0, it is necessary to log in from the OauthLogin application. This Application also takes some parameters. The parameters of the application are as follows.
{
"ms": {
"instance": "https://login.microsoftonline.com/",
"clientId": "",
"tenantId": "",
"redirectUri": "https://localhost:7149/sample-oauth2/get-token",
"scopes": [
"email",
"offline_access",
"https://outlook.office.com/SMTP.Send",
"https://outlook.office.com/IMAP.AccessAsUser.All",
"https://outlook.office.com/POP.AccessAsUser.All",
"https://outlook.office.com/EWS.AccessAsUser.All"
]
},
"google": {
"clientId": "",
"clientSecret": "",
"userId": "ornekmail@gmail.com",
"scopes": [
"https://mail.google.com/"
]
}
}
MS
The MS parameter in Json represents Microsoft and the values in it take the required values for Outlook. It is sufficient to change the clientId and tenantIds from these values. Other Parameters can be changed (except for redirectUri), but there is no need for it. You can make the necessary settings and provide the ClientId and TenantId information on https://portal.azure.com/.
The values in the Google parameter in Json get the required values for Gmail. It is sufficient to change the clientId, tenantId, userIds from these values.
After the required parameters for the OauthLogin Application are filled in as above, the application is run.
OauthLogin App
After the application is opened, a screen like the one below will appear. On this screen, it will be selected for which mail service (outlook, gmail) to log in, and then the resulting RefreshTokens will be added to the Configuration Table or Configuration Manager Application. In-app visuals and Sample RefreshToken are as in the image below.
When Login With Microsoft is selected, you need to paste a URL like the one below into your browser and then grant permissions from the browser.
If the operations are successful, the Browser True value will return and we will get the RefreshToken Information as in the image.
If the Login With Google option is selected, the browser will open automatically and write the refreshToken information on the console screen as in the image above.
Mail Service Parameters and Use of Refresh Tokens
We will need to add the refreshTokens we received above to the Configs created for MailService (OAuth2RefreshToken parameter) in our ConfigurationManager or Configuration tables. These Config details are explained in the "Mail Service - Configuration Parameters" document.
Basic Authentication
The setting we need to do for Basic Authentication will only be to enter the UserName and UserPassword fields. OAuth2RefreshToken, ClientId, ClientSecret, TenantId can be left blank.
Note: The MailService application primarily checks the UserPassword parameters. If these parameters are empty, then it looks at parameters such as OAuth2RefreshToken, ClientId, ClientSecret, TenantId, which are required for Oauth2.0. In short, if you want to work with Oatuh2.0, you need to leave the UserPassword information blank.