Wysyłanie e-maila poprzez Indy w formacie HTML z dodatkowymi załącznikami.

0

Witam.

Potrzebuję napisać program który wyśle mi w formacie HTML wiadomość ale z załączonym plikiem graficznym.

Problem polega na tym że jeden plik graficzny ma być w wiadomości wyświetlany a drugi ma być dołączony tylko (z możliwością pobrania i wydrukowania)

Znalazłem w necie kod pod Delphi i na tym się zatrzymałem bo... nie wiem jak przetłumaczyć kod na C++ Buildera.

Może ktoś Mi pomóc?

Link do oryginału tutaj :
http://delphi.cjcsoft.net/viewthread.php?tid=43366

Moje poprawki na razie to to :

 IdText idtTextPart;
 IdMessage1->Clear;
 IdMessage1->ContentType = "Multipart/Alternative";

 // add a plain text message part
 idtTextPart.TIdText.Create(IdMessage1.MessageParts,nil);
 idtTextPart.ContentType:='text/plain';
 idtTextPart.Body.Add('This is the plain part of the message.');
 // add the HTML message part
 idtTextPart:= TIdText.Create(IdMessage1.MessageParts,nil);
 idtTextPart.ContentType := 'text/html';
 idtTextPart.Body.add('');
 idtTextPart.Body.add('Testing...');
 idtTextPart.Body.add('Testing...');
 idtTextPart.Body.add('Testing...');
 idtTextPart.Body.add('');




 IdMessage1->From->Address = "[email protected]";
 IdMessage1->From->Name = "Me";
 IdMessage1->Sender->Address = "[email protected]";
 IdMessage1->Sender->Name = "Me";
 // add the recipients
 IdMessage1->Recipients->Clear();
 IdMessage1->Recipients->Add("[email protected]");
 IdMessage1->Subject = "Some Subject";



 // add an attachment
 TIdAttachment.Create(IdMessage1->MessageParts, "c:\attach.bmp");




 IdSMTP1->Host = "smtp.isp.com";
 IdSMTP1->Port = 25;
 IdSMTP1->Connect();
 IdSMTP1->Send(IdMessage1);
 IdSMTP1->Disconnect();

Czyli praktycznie zatrzymałem się na początku... Będę bardzo wdzięczny za pomoc :)

0

Ok... udało Mi się tak to pozmieniać że pozwoliło się uruchomić. Niestety wyskakuje Mi błąd i nie wysyła wiadomości... Wie ktoś czemu?

Obecna wersja :

 IdMessage1->Clear();
 IdMessage1->MessageParts->Add();
 IdMessage1->MessageParts->Add();

 IdMessage1->ContentType = "Multipart/Alternative";
 TIdText  *IdTextPart = (TIdText*)IdMessage1->MessageParts->Items[0];
 TIdText  *IdHtmlPart = (TIdText*)IdMessage1->MessageParts->Items[1];

 // add a plain text message part
// IdTextPart-> >Create(IdMessage1.MessageParts,nil);

 IdTextPart->ContentType = "text/plain";
 IdTextPart->Body->Add("This is the plain part of the message.");

 // add the HTML message part
 //IdTextPart:= IdTextPart.Create(IdMessage1.MessageParts,nil);

 IdHtmlPart->ContentType = "text/html";
 IdHtmlPart->Body->Add("<html><body bgcolor=\"red\">");
 IdHtmlPart->Body->Add("Testing...<br>");
 IdHtmlPart->Body->Add("Testing...<br>");
 IdHtmlPart->Body->Add("Testing...<br>");
 IdHtmlPart->Body->Add("</body></html>");

 IdMessage1->From->Name = Edit1->Text; //pobiera nazwę nadawcy wiadomości
 IdMessage1->From->Address = Edit2->Text; //pobiera adres e-mail nadawcy wiadomości
 IdMessage1->Recipients->EMailAddresses = Edit3->Text; // pobiera adres e-mail odbiorcy wiadomości
 IdMessage1->Subject = Edit5->Text; // pobiera tytuł (temat) wiadomości
 IdMessage1->Body->Append(Memo1->Text); //pobiera treść wiadomości

 IdSMTP1->Host = Edit4->Text; // pobiera adres serwera SMTP
 IdSMTP1->Password = Edit6->Text; // pobiera hasło nadawcy wiadomości
 IdSMTP1->UserId = Edit7->Text; // pobiera nazwę nadawcy wiadomości - ID użytkownika
 IdSMTP1->AuthenticationType = atLogin; // wymagana autoryzacja
 IdSMTP1->Port = 25;

 // add an attachment
 TIdAttachment *IdAtt = new TIdAttachment(IdMessage1->MessageParts, OpenDialog1->FileName);

 IdSMTP1->Connect();
 try
   {
    IdSMTP1->Send(IdMessage1);
   }
 __finally
   {
    IdSMTP1->Disconnect();
   }

1 użytkowników online, w tym zalogowanych: 0, gości: 1