Board index » delphi » Sending HTML Mails with Attachments

Sending HTML Mails with Attachments

Hello,

 i have the following Problem with the idMessage (idText, idAttachments)...
 i want to send
  HTML Mails, Text Mail, HTML Mail with Attachments, Text Mails with
Attachments.

   - if i recieve an message in outlook (Text withOUT Attachments) its
alright.
   - Text Messages can i send With or without Attachments, every time it
works fine!

BUT: if i send an HTML Message with Attachments, i see in the recieved
Message the Source Code of the Message, the Attachments are ok.

it is right that i can add the SourceCode/Text on two ways
1. "with TIdText.Create(msg.MessageParts) do
        begin
           ContentType := 'text/html';
           Body.Text := SourceText.Text;
       end;"

2. "Msg.Body.Assign(SourceText.Text);"

PLEASE HELP ME, i have this problem the last TWO Days, and i have no
time(project)... :)
How can i Add the MessageParts with Text, Html, Attachments and ...... on
the right way ?
sorry about my bad english, i hope you understand it.

 

Re:Sending HTML Mails with Attachments


  TIdText.Create(idMessage.MessageParts);

idMessage.MessageParts.Items[Pred(idMessage.MessageParts.Count)].ContentType
:= 'text/html';

TIdText(idMessage.MessageParts.Items[Pred(idMessage.MessageParts.Count)]).Bo
dy.Text := '<html><body>html test<hr><img src="test.jpg"></body></html>';

 TIdAttachment.Create(idMessage.MessageParts, 'w:\temp\test.jpg');

Quote
"#dK" <a...@nym.com> wrote in message

news:ba25jc$i48$01$1@news.t-online.com...
Quote
> Hello,

>  i have the following Problem with the idMessage (idText,
idAttachments)...
>  i want to send
>   HTML Mails, Text Mail, HTML Mail with Attachments, Text Mails with
> Attachments.

>    - if i recieve an message in outlook (Text withOUT Attachments) its
> alright.
>    - Text Messages can i send With or without Attachments, every time it
> works fine!

> BUT: if i send an HTML Message with Attachments, i see in the recieved
> Message the Source Code of the Message, the Attachments are ok.

> it is right that i can add the SourceCode/Text on two ways
> 1. "with TIdText.Create(msg.MessageParts) do
>         begin
>            ContentType := 'text/html';
>            Body.Text := SourceText.Text;
>        end;"

> 2. "Msg.Body.Assign(SourceText.Text);"

> PLEASE HELP ME, i have this problem the last TWO Days, and i have no
> time(project)... :)
> How can i Add the MessageParts with Text, Html, Attachments and ...... on
> the right way ?
> sorry about my bad english, i hope you understand it.

Re:Sending HTML Mails with Attachments


That one is not good, first text you must create two times, so :

 IdMessage.Recipients.EMailAddresses := 'yourm...@domain.com';

  TIdText.Create(idMessage.MessageParts);
  TIdText.Create(idMessage.MessageParts);

idMessage.MessageParts.Items[Pred(idMessage.MessageParts.Count)].ContentType
:= 'text/html';

TIdText(idMessage.MessageParts.Items[Pred(idMessage.MessageParts.Count)]).Bo
dy.Text := '<html><body><img src="test.jpg"></body></html>';

 TIdAttachment.Create(idMessage.MessageParts, 'w:\temp\test.jpg');
 TIdAttachment.Create(idMessage.MessageParts, 'w:\temp\otherFile.txt');

 IdSmtp.Connect;
 IdSmtp.Send(IdMessage);
 IdSmtp.Disconnect;

Other Threads