Send a mail with TIdSMTP with a signature |
|
Re: Send a mail with TIdSMTP with a signature |
|
Roberto wrote:
> I try this code but in Outlook I see only a square with a little x
> inside.
You did not set up the TIdMessage correctly. It needs to be more like this
instead:
{code}
IdMessage1.ContentType := 'multipart/related; type="text/html"';
IdText1 := TIdText.Create(IdMessage1.MessageParts, nil);
IdText1.ContentType := 'text/html';
IdText1.Body.Add('');
IdText1.Body.Add('');
IdText1.Body.Add('');
IdText1.Body.Add(myText);
IdText1.Body.Add('');
IdText1.Body.Add('');
IdText1.Body.Add('');
IdAttach := TIdAttachmentFile.Create(IdMessage1.MessageParts, 'mypath\myjpeg.jpg');
IdAttach.ContentType := 'image/jpeg';
IdAttach.ContentDisposition := 'inline';
IdAttach.FileIsTempFile := False;
IdAttach.ContentID := 'myjpeg';
IdAttach.DisplayName := 'Logo';
{code}
The important things are:
1. You are using the wrong TIdMessage.ContentType value. The ContentType
needs to be "multipart/related", with a "type" attribute indicating which
child part is the main part of the relationship (in this case, the HTML).
That tells Outlook (or any other MIME reader) that multiple MIME parts are
related to each other.
2. You are using the wrong TIdAttachment.ContentID value. The ContentID
needs to match the value of the "cid:" url used in the HTML tag. That
allows the content of one MIME part to refer to the content of another MIME
part within the relationship.
I suggest you read the following article I wrote on the Indy website:
HTML Messages
http://www.indyproject.org/sockets/blogs/RLebeau/2005_08_17_A.aspx
Also this one:
New HTML Message Builder class
http://www.indyproject.org/sockets/blogs/RLebeau/20080116.aspx
Your code could be re-written using TIdMessageBuilderHtml as follows:
{code}
with TIdMessageBuilderHtml.Create do
try
Html.Add('');
Html.Add('');
Html.Add('');
Html.Add(myText);
Html.Add('');
Html.Add('');
Html.Add('');
with HtmlFiles.Add('mypath\myjpeg.jpg', 'myjpeg') do
begin
ContentType := 'image/jpeg';
Name := 'Logo';
end;
FillMessage(IdMessage1);
finally
Free;
end;
{code}
--
Remy Lebeau (TeamB)
|