Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion EmailOAuthDm.dfm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
object EmailOAuthDataModule: TEmailOAuthDataModule
OldCreateOrder = True
OnCreate = DataModuleCreate
OnDestroy = DataModuleDestroy
Height = 3000
Expand Down
17 changes: 13 additions & 4 deletions EmailOAuthDm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface
, IdSASLCollection
, IdMessage
, IdMessageClient
, IdAttachmentFile
, IdPOP3
, IdBaseComponent
, IdComponent
Expand All @@ -35,6 +36,7 @@ interface
, IdSASL.OAuth.Base
, Email.Demo.Types
, windows

;

type
Expand Down Expand Up @@ -73,7 +75,7 @@ TEmailOAuthDataModule = class(TDataModule)
procedure Authenticate;
procedure ClearAuthentication;
procedure SetupAuthenticator;
procedure SendMessage(const destAddress: string; const Path: String);
procedure SendMessage(const Subject : string ; const Body : string ; const destAddress: string; const Path: String; const attachmentFiles: array of string);
procedure CheckIMAP;
procedure CheckPOP;
end;
Expand Down Expand Up @@ -199,10 +201,11 @@ procedure TEmailOAuthDataModule.ClearAuthentication;
SetupAuthenticator;
end;

procedure TEmailOAuthDataModule.SendMessage(const destAddress: string; const Path: String);
procedure TEmailOAuthDataModule.SendMessage(const Subject : string ; const Body : string ; const destAddress: string; const Path: String; const attachmentFiles: array of string);
var
IdMessage: TIdMessage;
xoauthSASL : TIdSASLListEntry;
i: Integer;
begin
// if we only have refresh_token or access token has expired
// request new access_token to use with request
Expand Down Expand Up @@ -242,8 +245,14 @@ procedure TEmailOAuthDataModule.SendMessage(const destAddress: string; const Pat
IdMessage.From.Name := Provider.ClientName;
IdMessage.ReplyTo.EMailAddresses := IdMessage.From.Address;
IdMessage.Recipients.Add.Text := destAddress;
IdMessage.Subject := 'Hello World';
IdMessage.Body.Text := 'Hello Body';
IdMessage.Subject := Subject;
IdMessage.Body.Text := Body;
for i := Low(attachmentFiles) to High(attachmentFiles) do
begin
if FileExists(attachmentFiles[i]) then
TIdAttachmentFile.Create(IdMessage.MessageParts, attachmentFiles[i])
end;


IdSMTP1.Send(IdMessage);
IdSMTP1.Disconnect;
Expand Down
4 changes: 2 additions & 2 deletions GMailAuthDemo.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ program GMailAuthDemo;
uses
Vcl.Forms,
Unit2 in 'Unit2.pas' {Form2},
Globals in 'Globals.pas', // rename from globals.sample.pas and update contents if missing
IdSASL.OAuth.XOAUTH2 in 'IdSASL.OAuth.XOAUTH2.pas',
EmailOAuthDm in 'EmailOAuthDm.pas' {EmailOAuthDataModule: TDataModule},
IdSASL.OAuth.OAuth2Bearer in 'IdSASL.OAuth.OAuth2Bearer.pas',
REST.Authenticator.EnhancedOAuth in 'REST.Authenticator.EnhancedOAuth.pas',
Email.Demo.Types in 'Email.Demo.Types.pas',
IdSASL.OAuth.Base in 'IdSASL.OAuth.Base.pas';
IdSASL.OAuth.Base in 'IdSASL.OAuth.Base.pas',
Globals.Sample in 'Globals.Sample.pas';

{$R *.res}

Expand Down
Loading