unit AS_Globals;
interface
uses
Dialogs, Forms, SysUtils, Windows, StdCtrls, Classes, Clipbrd, IdMessage,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,
IdMessageClient, IdSMTPBase, IdSMTP;
type
TIdSMPTP =
class(TIdSMTPBase);
//Functions
function fnSendEMail(sHost, sUsername, sPassword, sFrom, sSenderEMail, sReceipt,
sSubject :
String; strlBody : TStrings; iPort : Integer) : Boolean;
implementation
//******************************************************************************
// *
// F U N C T I O N S *
// *
//******************************************************************************
//******************************************************************************
// fnSendEMail --> Send E-Mail *
// Parameter --> sHost = E-Mail Server *
// sUsername = E-Mail User Account *
// sPassword = E-Mail User Account Password *
// sFrom = From Text *
// sSenderEMail = E-Mail Adress from Sender *
// sReceipt = Receipt E-Mail Adress *
// sSubject = E-Mail Subject *
// strlBody = E-Mail Text *
// iPort = E-Mail Server Port *
// Return --> Boolean (True/False) *
//******************************************************************************
function fnSendEMail(sHost, sUsername, sPassword, sFrom, sSenderEMail, sReceipt,
sSubject :
String; strlBody : TStrings; iPort : Integer) : Boolean;
var
SMTP : TIdSMTP;
idMessage : TIdMessage;
begin
Result := True;
//Create TIdSMTP and TIdMessage Componente
SMTP := TIdSMTP.Create();
idMessage := TIdMessage.Create();
//Configure SMPTP
SMTP.Host := sHost;
SMTP.Username := sUsername;
SMTP.Password := sPassword;
SMTP.Port := iPort;
//Configure idMessage
idMessage.From.Text := sFrom;
idMessage.Sender.Text := sSenderEMail;
idMessage.Recipients.EMailAddresses := sReceipt;
idMessage.Subject := sSubject;
idMessage.Body.Clear;
idMessage.Body := strlBody;
//Send E-Mail
Try
SMTP.Connect;
SMTP.Send(idMessage);
SMTP.Disconnect;
Except
Result := False;
If SMTP.Connected = True
Then
Begin
Try
SMTP.Disconnect;
Except
MessageDlg('
Could not disconnect from the E-Mail Server: ' + sHost, mtError, [mbOK], 0);
End;
End;
MessageDlg('
Could not send E-Mail to: ' + sReceipt, mtError, [mbOk], 0);
End;
//Destroy TIdSMTP and TIdMessage Componente
SMTP.Free;
idMessage.Free;
end;