Advertisement
D98rolb

SendMail with nonblocking call

Oct 16th, 2024 (edited)
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.51 KB | None | 0 0
  1. procedure MakeInvoiceClick(Sender: TObject)
  2. begin
  3.   if MakeInvoice(SelectedParcelList) then
  4.     UpDateParcels(SelectedParcelList)
  5.   else
  6.     ShowMessage('Make invoice failed');
  7. end;
  8.  
  9. function MakeInvoice(ASelectedParcelList: TParcelList): Boolean;
  10. var
  11.   oParcel: TParcel;
  12. begin
  13.   for oParcel in ASelectedParcelList do
  14.   begin
  15.     if oParcel.Electronic then
  16.       Result := MakeEInvoice(oParcel)
  17.     else if oParcel.MailByPDF then
  18.       Result := MakePDFInvoice(oParcel);  
  19.   end;
  20. end;
  21.  
  22. function MakePDFInvoice(AParcel: TParcel): Boolean
  23. var
  24.   oPDF: string;
  25. begin
  26.   oPDF := MakePDF(AParcel);
  27.   Result := Mail.SendWait(UserData, oPDF);    
  28. end;
  29.  
  30. function TMail.SendWait(AUserData: TUSerData; const APDF: string): Boolean;
  31. begin
  32.   if GetSetting.UseSendGrid then
  33.     Result := SendMailWithGrid(AUserData, APDF)       // <-- Blocking
  34.   else if GetSetting.UseOutLook then
  35.     Result := SendMailWithOutLook(AUserData, APDF)    // <-- None blocking
  36.   else if GetSetting.UseSMTP then
  37.     Result := SendMailWithSMTP(AUserData, APDF);      // <-- Blocking
  38. end
  39.  
  40. function TMail.SendWaitWithOutLook(AUserData: TUSerData; const APDF: string): Boolean;
  41. begin
  42.   InitAuthentication;
  43.   Connect;
  44. end;
  45.  
  46. // Event called after successful authentication and Connect
  47. procedure TMail.Connected(Sender: TObject);
  48. begin
  49.   ConfigureEmail;
  50.   SendEmailMessage(UserData, Attachement);
  51. end;
  52.  
  53. // Event called after successful send an email
  54. procedure TMail.MessageSent(Sender: TObject; ARequestResult: TMailResult);
  55. begin
  56.  
  57. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement