Subject: | DELPHI7 INDY10 - HTML emails with related attachments |
Posted by: | ma…@futurelinksw.co.uk |
Date: | Tue, 27 Nov 2007 |
Hi all,
I am currently adding an email compose section to a program and having
issues with sending html emails with plaintext and related images. When I
send the message it shows up perfectly in webmail and mozilla thunderbird
but when I view the message with outlook the inline images just show as red
crosses. This is not the outlook privacy download images problem as far as I
can tell, all I can think is I am missing something creating the IdMessage
that is required.
I am at a standstill with this so any help would be more than greatfully
received :)
Regards,
Matt Leonard
Here is a basic code sample of how I am putting the IdMessage together:
procedure TForm1.Button1Click(Sender: TObject);
var
attachimg : TIdAttachmentFile;
emptybody, textbody, htmlbody : TIdText;
begin
emptybody := TIdText.Create(IdMessage1.MessageParts, nil);
emptybody.ContentType := 'multipart/alternative';
emptybody.ParentPart := -1;
textbody := TIdText.Create(IdMessage1.MessageParts, nil);
textbody.Body.Text := 'plain text part';
textbody.ContentType := 'text/plain';
textbody.ParentPart := 0;
htmlbody := TIdText.Create(IdMessage1.MessageParts, nil);
htmlbody.body.text := '<p>This is a email saying weeeeeee.</p><img
src="CID:12345" />';
htmlbody.ContentType := 'text/html';
htmlbody.ParentPart := 0;
Attachimg := TIdAttachmentFile.Create(IdMessage1.MessageParts,
'c:\x1.jpg');
Attachimg.ExtraHeaders.Values['content-id'] := '12345';
Attachimg.FileIsTempFile := true;
Attachimg.ContentDisposition := 'inline';
Attachimg.ContentType := 'image/jpeg';
Attachimg.FileName := 'x1.jpg';
Attachimg.ParentPart := -1;
IdMessage1.ContentType := 'multipart/related;
type="multipart/alternative"';
IdMessage1.CharSet:='iso-8859-1';
IdMessage1.Encoding:=meMIME;
IdMessage1.From.Address := 'ma…@futurelinksw.co.uk';
IdMessage1.From.Name := 'matt';
IdMessage1.Recipients.EMailAddresses := 'ma…@futurelinksw.co.uk';
IdMessage1.Subject := 'test';
IdSMTP1.Host := 'worthy';
IdSMTP1.Port := 25;
try
IdSMTP1.Connect();
try
IdSMTP1.Send(IdMessage1);
except
on E: Exception do
showmessage('Send Failed ' + E.Message);
end;
finally
IdMessage1.MessageParts.Clear;
IdSMTP1.Disconnect;
showmessage('Send Successful');
end;
end;