Bonjour,

Je n'arrive pas très bien a comprendre comment avec Indy je peux envoyer un mail avec du code HTML avec une image à afficher dans le corps + un fichier joint. J'ai beau essayer j'arrive pas, tout s'affiche ...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
procedure TForm1.Button5Click(Sender: TObject);
var
 
IdAttach: TIdAttachmentFile ;
  IdText1: TIdText;
  NameFile : String;
begin
 
IdSMTP1.Host := 'smtp.free.fr';
IdSMTP1.Port := 25;
IdSMTP1.Username := '';
IdSMTP1.Password := '';
IdMessage1.From.Name:='pat';
IdMessage1.From.Address := 'test@free.fr';
IdMessage1.Recipients.EMailAddresses := 'test@free.fr';
IdMessage1.Subject :='test';
 
 
IdMessage1.ContentType:='multipart/mixed';
 
// Fichier joint dans le corps HTML
NameFile:='c:\hotline.jpg';
IdAttach := TIdAttachmentFile.Create( IdMessage1.MessageParts,NameFile);
IdAttach.ContentDisposition :='inline';
IdAttach.ContentTransfer := 'base64';
IdAttach.ExtraHeaders.Values['content-id'] :=ExtractfileName(NameFile);
 
// Fichier à attacher dans le mail
IdAttach := TIdAttachmentFile.Create( form1.IdMessage1.MessageParts,'c:\bamby.jpg');
 
 
 
IdMessage1.Body.Text:=Memo2.Text;
IdText1 := TIdText.Create( IdMessage1.MessageParts,  IdMessage1.Body);
IdText1.ContentType := 'text/html';
 
 
try
    try
       IdSMTP1.Connect;
       IdSMTP1.Send( IdMessage1);
    except
      on E:Exception do
        ShowMessage('Failed to send Email!'+#13#10+e.message);
    end;
  finally
    if  IdSMTP1.Connected then
       IdSMTP1.Disconnect;
  end;
 
 
end;
Le memo2 contient :

Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE HTML PUBLIC 
"-//W3C//DTD HTML 4.0 
Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-
Type" CONTENT="text/html; 
charset=iso-8859-1">
<BODY>
<P><IMG height=48 
src="cid:hotline.jpg" width=85
border=0></P>
</BODY></HTML>