Advertisement
Guest User

Untitled

a guest
Feb 18th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.33 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, smtpsend,  winsock,
  7.   Dialogs,blcksock,synautil,synacode, Buttons;
  8.  
  9. type
  10. TForm1 = class(TForm)
  11.     SpeedButton1: TSpeedButton;
  12.     procedure SpeedButton1Click(Sender: TObject);
  13.     procedure FormCreate(Sender: TObject);
  14.   private
  15.     { Private declarations }
  16.   public
  17.     function SendEmailNotification(EventText : string): boolean;
  18.     function myIPadd: string;
  19.   end;
  20.  
  21. TNotificationThread = class(TThread)
  22.     public
  23.       procedure Execute; override;
  24.     end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.   emailmsg : TStrings;
  29.   emlform, emlto, emlhost, emlusername, emlpassword : string;
  30.  
  31. implementation
  32.  
  33. {$R *.dfm}
  34.  
  35.  
  36.  
  37. function TForm1.myIPadd: string;
  38. type
  39.     TaPInAddr = array [0..10] of PInAddr;
  40.     PaPInAddr = ^TaPInAddr;
  41. var
  42.     phe : PHostEnt;
  43.     pptr : PaPInAddr;
  44.     Buffer : array [0..63] of char;
  45.     i : Integer;
  46.     GInitData : TWSADATA;
  47.  
  48. begin
  49.     WSAStartup($101, GInitData);
  50.     Result := '';
  51.     GetHostName(Buffer, SizeOf(Buffer));
  52.     phe :=GetHostByName(buffer);
  53.     if phe = nil then Exit;
  54.     pptr := PaPInAddr(Phe^.h_addr_list);
  55.     i := 0;
  56.     while pptr^[i] <> nil do
  57.         begin
  58.             result:=StrPas(inet_ntoa(pptr^[i]^));
  59.             Inc(i);
  60.         end;
  61.     WSACleanup;
  62. end;
  63.  
  64. function TForm1.SendEmailNotification(EventText : string): boolean;
  65. var
  66.     emailmsg : TStrings;
  67.     emailsubject : string;
  68.     sendresult : boolean;
  69.     ipa : string;
  70.  
  71. begin
  72.     emailmsg := TStringList.Create;
  73.     ipa := myIPadd;
  74.     with emailmsg do
  75.         begin
  76.             Add('Hi');
  77.             Add('');
  78.             Add('This is a message from the Lyracon Server at '+ipa);
  79.             Add('');
  80.             Add(EventText);
  81.             Add('');
  82.             Add('Many thanks');
  83.             Add('');
  84.             Add('Lyrcacon Server');
  85.         end;
  86.  
  87.     emailsubject := 'Activation Notification From Lyracon At '+ipa;
  88.     sendresult := SendToEx(emlform, emlto, emailsubject, emlhost, emailmsg, emlusername, emlpassword);
  89.     result := sendresult;
  90. end;
  91.  
  92. procedure TNotificationThread.Execute;
  93. begin
  94.     Form1.SendEmailNotification('THIS IS A THREADED EMAIL');
  95. end;
  96.  
  97.  
  98. procedure TForm1.SpeedButton1Click(Sender: TObject);
  99.  
  100. begin
  101.     TNotificationThread.Create(false);
  102. end;
  103.  
  104. procedure TForm1.FormCreate(Sender: TObject);
  105. begin
  106.   emlform := 'from@hdomain.com';
  107.   emlto := 'to@domain.co.uk';
  108.   emlhost := 'myemailserver';
  109.   emlusername := 'user@server.co.uk';
  110.   emlpassword := 'myemailpassword';
  111. end;
  112.  
  113. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement