Subject: | mail with attachment |
Posted by: | Mieke (jaja…@planet.nl) |
Date: | Tue, 10 Feb 2009 |
Hi,
I'm trying to send an email with attachment using TidSMTP and TidMessage in
the following way. Collegues tell me it works in indy9, I use indy 10.1.5I
(delphi2007) and can't get it working. All I want is to sen an email in
which I use font 'Arial 10' in the mailbody and add an attachmentfile. Using
the code I receive an email wit h2 attachments: 1 with the name
ATT000107.htm with contains the string 'bodyHTML' and 1 with my worddoc
(this is correct).
Am I doing something wrong or is it a problem in indy 10.1.5?
Thank you,
Mieke
This is the code I use:
var
TextPart : TIdText;
Attachment : TIdAttachmentFile;
sDocument : string;
begin
sDocument := 'c:\mailtest.doc';
MyMessage.Clear;
MyMessage.IsEncoded := True ;
MyMessage.CharSet := 'iso-8859-1';
MyMessage.Encoding := meMIME;
MyMessage.ContentType := 'multipart/mixed';
MyMessage.Subject := 'testmail';
{initializeren}
smtp.Host := ..host
smtp.Port := ..poost
MyMessage.From.Text := ..afzender
MyMessage.Body.Clear;
TextPart := TIdText.Create(MyMessage.MessageParts);
TextPart.ContentType := 'text/html';
TextPart.Body.Clear;
TextPart.Body.Text := 'BodyHTML';
MyMessage.Recipients.Add.Address := 'te…@test.nl';
Attachment := TIdAttachmentFile.Create(MyMessage.MessageParts, sDocument);
Attachment.ContentType := 'text/html';
Attachment.ContentDisposition := 'attachment';
Attachment.Headers.Add(sDocument);
Attachment.ExtraHeaders.Values['content-id']:= sDocument;
smtp.Connect;
smtp.Send(MyMessage);
FreeAndNil(Attachment);
end;{mailen test}