send email for outlook (#10703)
driver implementation for sending emails with microsoft --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
This commit is contained in:
@ -4,7 +4,8 @@ export const getMicrosoftApisOauthScopes = () => {
|
||||
'email',
|
||||
'profile',
|
||||
'offline_access',
|
||||
'Mail.Read',
|
||||
'Mail.ReadWrite',
|
||||
'Mail.Send',
|
||||
'Calendars.Read',
|
||||
'User.Read',
|
||||
];
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { assertUnreachable, ConnectedAccountProvider } from 'twenty-shared';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { GmailClientProvider } from 'src/modules/messaging/message-import-manager/drivers/gmail/providers/gmail-client.provider';
|
||||
import { MicrosoftClientProvider } from 'src/modules/messaging/message-import-manager/drivers/microsoft/providers/microsoft-client.provider';
|
||||
|
||||
interface SendMessageInput {
|
||||
body: string;
|
||||
@ -13,7 +15,10 @@ interface SendMessageInput {
|
||||
|
||||
@Injectable()
|
||||
export class MessagingSendMessageService {
|
||||
constructor(private readonly gmailClientProvider: GmailClientProvider) {}
|
||||
constructor(
|
||||
private readonly gmailClientProvider: GmailClientProvider,
|
||||
private readonly microsoftClientProvider: MicrosoftClientProvider,
|
||||
) {}
|
||||
|
||||
public async sendMessage(
|
||||
sendMessageInput: SendMessageInput,
|
||||
@ -43,9 +48,30 @@ export class MessagingSendMessageService {
|
||||
});
|
||||
break;
|
||||
}
|
||||
case ConnectedAccountProvider.MICROSOFT:
|
||||
// TODO: Implement Microsoft provider
|
||||
throw new Error('Microsoft provider not implemented');
|
||||
case ConnectedAccountProvider.MICROSOFT: {
|
||||
const microsoftClient =
|
||||
await this.microsoftClientProvider.getMicrosoftClient(
|
||||
connectedAccount,
|
||||
);
|
||||
|
||||
const message = {
|
||||
subject: sendMessageInput.subject,
|
||||
body: {
|
||||
contentType: 'Text',
|
||||
content: sendMessageInput.body,
|
||||
},
|
||||
toRecipients: [{ emailAddress: { address: sendMessageInput.to } }],
|
||||
};
|
||||
|
||||
const response = await microsoftClient
|
||||
.api(`/me/messages`)
|
||||
.post(message);
|
||||
|
||||
z.string().parse(response.id);
|
||||
|
||||
await microsoftClient.api(`/me/messages/${response.id}/send`).post({});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assertUnreachable(
|
||||
connectedAccount.provider,
|
||||
|
||||
@ -91,7 +91,8 @@ Then you can set the following environment variables:
|
||||
|
||||
On Microsoft Azure Console enable the following APIs in "Permissions":
|
||||
|
||||
- Microsoft Graph: Mail.Read
|
||||
- Microsoft Graph: Mail.ReadWrite
|
||||
- Microsoft Graph: Mail.Send
|
||||
- Microsoft Graph: Calendars.Read
|
||||
- Microsoft Graph: User.Read.All
|
||||
- Microsoft Graph: openid
|
||||
@ -99,6 +100,8 @@ On Microsoft Azure Console enable the following APIs in "Permissions":
|
||||
- Microsoft Graph: profile
|
||||
- Microsoft Graph: offline_access
|
||||
|
||||
Note: "Mail.ReadWrite" and "Mail.Send" are only mandatory if you want to send emails using our workflow actions. You can use "Mail.Read" instead if you only want to receive emails.
|
||||
|
||||
### Authorized redirect URIs
|
||||
|
||||
You need to add the following redirect URIs to your project:
|
||||
@ -111,8 +114,9 @@ You need to add the following redirect URIs to your project:
|
||||
- 'email'
|
||||
- 'profile'
|
||||
- 'offline_access'
|
||||
- 'Mail.Read'
|
||||
- 'Calendars.Read
|
||||
- 'Mail.ReadWrite'
|
||||
- 'Mail.Send'
|
||||
- 'Calendars.Read'
|
||||
|
||||
### If your app is in test mode
|
||||
|
||||
|
||||
Reference in New Issue
Block a user