procedure
TForm1.AttachBtnClick(Sender: TObject);
var
BackupName: string;
begin
{ selects
the attachment to send and changes the file extension }
{ if the
attachment is an executable due to some mail systems }
{ not
allowing executables through thier systems in case they }
{ contain
viruses or trojans etc... then if option is checked }
{ adds text
to the bottom of the message to inform the recipient }
{ to rename
the file upon retrieval }
if
Opendialog.Execute Then // open the opendialog
{ if the extension is *.exe then backup and
rename it }
if ExtractFileExt(Opendialog.FileName) =
'.exe' then
begin
BackupName :=
ExtractFileName(OpenDialog.FileName);
BackupName :=
ChangeFileExt(BackupName, '.e');
Mail.PostMessage.Attachments.Add(BackupName);
end;
{ if the InformBox is checked and the
extension is *.exe }
{ write some info for the recipient to
tell them to rename it }
if (InformBox.Checked = true) and
(ExtractFileExt(Opendialog.FileName) = '.exe') then
begin
InformBox.Checked := false; //
this two lines are so that if the user attaches more than one
InformBox.Enabled := false; //
*.exe then they don't have loadsa text at the end of the message
Msg.Lines.Add('');
Msg.Lines.Add('');
Msg.Lines.Add('The Attached File is an Executable');
Msg.Lines.Add('therefore it has
been renamed so that mail systems don''t automatically remove it');
Msg.Lines.Add('First, if this
e-mail has been sent to you by someone you don''t know/trust');
Msg.Lines.Add('we advise that you
check it for viruses/trojans etc...');
Msg.Lines.Add('then save it in an
isolated part of your hard-drive and rename it so that the extension reads
".exe"');
end
else
{ otherwise just add the attachment }
if ExtractFileExt(Opendialog.FileName)
<> '.exe' then
Mail.Postmessage.Attachments.Add(Opendialog.FileName);
-------
Msg=Memo
Mail=TNSmtp?
==============================
inne
=========
procedure
TfrmMessageEditor.btnAttachmentClick(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
TIdAttachment.Create(IdMsgSend.MessageParts, OpenDialog1.FileName);
ResetAttachmentListView;
end;
================================
new
----
OpenDialog1.Filter
:= 'AllFiles (*.*)|*.*';
OpenDialog1.Execute;
Label4.Caption
:= 'Attachment: ' + ExtractFileName(OpenDialog1.FileName);
NMSMTP1.PostMessage.Attachments.Add(OpenDialog1.FileName);
end;
=====================================================
TIdAttachment.Create (Indy help)
Constructor
for the collection item.
constructor
Create(Collection: TIdMessageParts; const AFileName: TFileName);
Parameters
Collection:
TIdMessageParts
Collection
that owns the collection item.
const
AFileName: TFileName = ''
File name
for the attachment. Default values is ''.
Description
Create is
the constructor for the collection item, and is used to create a new
TIdAttachment object and adds it to the TIdMessageParts collection specified by
the Collection parameter.
AFileName
is an optional parameter that specifies the initial name of the file to be
attached with the TIdAttachment.
Create
calls the inherited Create method to initialize the object instance, and
assigns AFileName to the FileName property.
=============
Ten
DZiała!!!!!
procedure
TForm1.SelButton3Click(Sender: TObject);
begin
(*if
opendialog1.Execute
then
begin
idmessage1.Body.Add(Opendialog1.FileName); //moje, ale czy dobrze?
Memo2.Lines.Add(Opendialog1.FileName+
#13#10 + '__________________'); *)
if OpenDialog1.Execute then
begin
TIdAttachment.Create(IdMessage1.MessageParts, OpenDialog1.FileName);
Memo2.Lines.Add(Opendialog1.FileName+
#13#10 + '__________________')
end;
end;
==============================