home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 November
/
Chip_2002-11_cd1.bin
/
zkuste
/
delphi
/
kompon
/
d567
/
MMAILER.ZIP
/
mMailer.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2002-08-29
|
7KB
|
225 lines
{
----------------------------------------------------------
MAS-CompMaker was used to generate this code
MAS-CompMaker, 2000-2002« Mats Asplund
----------------------------------------------------------
Component Name: TmMailer
Author: Mats Asplund
Creation: 2002-08-09
Version: 1.0
Description: A mailsender component
Credit: (place your credits here)
E-mail: masprod@telia.com
Site: http://go.to/mdp
Legal issues: All rights reserved 2002« by Mats Asplund
Usage:
This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it
and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented,
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
4. If you decide to use this software in any of your applications.
Send me an EMail and tell me about it.
Quick Reference:
TmMailer inherits from TComponent.
Key-Properties:
Body: The Body-part of the EMAil-message.
Attachments
AtttachedFiles: Add the files you wan't to attache to this StringList,
FileName: or just write filenames here.
Host: Your Internet provider.
UserId: Your UserId.
Password: Your Password.
Priority: Five levels of priority for the message.
From: The sender EMail-address.
Recipients: Add recipients to this list.
Subject: The messages subject.
HTML: If true the EMail is marked as HTML else as plain text.
Key-Events:
OnSendError: Event fired if there is an exception while sending.
Key-Methods:
Send: Sends the message.
--------------------------------------------------------------------------------
}
unit mMailer;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdMessage, IdComponent,
IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP, IdEMailAddress;
type
TOnSendError = procedure(Sender: TObject; ErrorMsg: string) of object;
TAttachement = class(TPersistent)
private
fFileName: TFileName;
fAttachedFiles: TStrings;
fOwner: TComponent;
procedure SetAttachedFiles(const Value: TStrings);
procedure SetFileName(const Value: TFileName);
public
constructor Create(Owner: TComponent);
published
property FileName: TFileName read fFileName write SetFileName;
property AttachedFiles: TStrings read fAttachedFiles write SetAttachedFiles;
end;
TmMailer = class(TComponent)
private
fAbout: string;
fHost: string;
fUserId: string;
fFrom: TIdEMailAddressItem;
fRecipients: TIdEMailAddressList;
fBody: TStrings;
fSubject: string;
fMsg: TIdMessage;
fSMTP: TIdSMTP;
fPassword: string;
fHTML: Boolean;
fPriority: TIdMessagePriority;
fOnSendError: TOnSendError;
fAttachments: TAttachement;
procedure SetCop(Value: string);
procedure SetBody(const Value: TStrings);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Send;
published
property Body: TStrings read fBody write SetBody;
property Attachments: TAttachement read fAttachments write fAttachments;
property Host: string read fHost write fHost;
property UserId: string read fUserId write fUserId;
property Password: string read fPassword write fPassword;
property Priority: TIdMessagePriority read fPriority write fPriority default
ID_MSG_PRIORITY;
property From: TIdEMailAddressItem read fFrom write fFrom;
property Recipients: TIdEMailAddressList read fRecipients write fRecipients;
property Subject: string read fSubject write fSubject;
property HTML: Boolean read fHTML write fHTML;
property OnSendError: TOnSendError read fOnSendError write fOnSendError;
property About: string read fAbout write SetCop;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MAs Prod.', [TmMailer]);
end;
constructor TmMailer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fAttachments:= TAttachement.Create(self);
fAttachments.fAttachedFiles:= TStringList.Create;
fBody:= TStringList.Create;
fRecipients:= TIdEMailAddressList.Create(Self);
fFrom:= TIdEMailAddressItem.Create(nil);
fMsg:= TIdMessage.Create(Self);
fSMTP:= TIdSMTP.Create(Self);
fHTML:= true;
fPriority:= mpNormal;
fAbout:= 'Version 1.0, 2002 « Mats Asplund, http://go.to/masdp';
end;
destructor TmMailer.Destroy;
begin
inherited Destroy;
end;
procedure TmMailer.Send;
var
n: integer;
begin
try
for n:= 0 to fAttachments.AttachedFiles.Count -1 do
TIdAttachment.Create(fMsg.MessageParts, fAttachments.AttachedFiles[n]);
fMsg.SetBody(fBody);
fMsg.Recipients:= fRecipients;
fMsg.From:= fFrom;
fMsg.Subject:= fSubject;
if fHTML then
fMsg.ContentType:= 'text/HTML'
else
fMsg.ContentType:= 'text/plain';
fSMTP.UserId:= fUserId;
fSMTP.Password:= fPassword;
fSMTP.Host:= fHost;
fSMTP.Connect;
fSMTP.Send(fMsg);
fSMTP.Disconnect;
except
on E: Exception do
if Assigned(fOnSendError) then
fOnSendError(Self, E.Message);
end;
end;
procedure TmMailer.SetBody(const Value: TStrings);
begin
fBody.Assign(Value);
end;
procedure TmMailer.SetCop(Value: string);
begin
Exit;
end;
{ TAttachement }
constructor TAttachement.Create(Owner: TComponent);
begin
inherited Create;
fOwner:= Owner;
end;
procedure TAttachement.SetAttachedFiles(const Value: TStrings);
begin
fAttachedFiles.Assign(Value);
end;
procedure TAttachement.SetFileName(const Value: TFileName);
begin
fFileName:= Value;
if (fFileName <> '') and (fAttachedFiles.IndexOf(fFileName) = -1) then
begin
fAttachedFiles.Add(fFileName);
if csDesigning in fOwner.ComponentState then
Showmessage('Added: ' + fFileName + ' to AttachedFiles.');
end;
end;
end.