Page 1 of 1

TMail with html body and attachment

Posted: Wed Jul 04, 2007 12:58 pm
by yury
hi everyone,

I´m using a TMail class to send mails, it´s work fine, but i have one question:

when i want send email with html body i do this:

Code: Select all

cSubject = "Testing Html Body"

cNoteText = nil

cMsgType = nil

cConversationID = nil

dDate = Date()

cTime = Time()

lReceipt = .F.

lFromUser = .T.

aOrigin = {mymail@mymail.com}

aRecipients = {yourmail@yourmail.com}

aFiles = {{"c:\MyDocuments\MyHtml.htm","MyHtml.htm"}}

oMail:=TMail():New(cSubject ,;
                             cNoteText ,;
                             cMsgType ,;
                             cConversationID ,;
                             dDate,;
                             cTime,;
                             lReceipt,;
                             lFromUser,;
                             aOrigin,;
                             aRecipients,;
                             aFiles)
it´s works great... :D

but if i need attach other file (a pdf file, for example), the html body is not created, and the mail has now 2 attach files, a html file and a pdf file...
:(

Code: Select all

aFiles = {{"c:\MyDocuments\MyHtml.htm","MyHtml.htm"},{"c:\MyDocuments\MyPdf.pdf","MyPdf.pdf"}}
i need an email with a html body and other file attached...

Many thanks :wink:

Posted: Fri Jul 06, 2007 1:48 pm
by yury
nothing ????

Posted: Fri Jul 06, 2007 2:35 pm
by Detlef Hoefner
yury wrote:nothing ????
Yuri,

you must understand that emails with a html body are normal emails where the email text is formatted via html tags.

The fact that you see a html body is depending on your email client program. This has nothing to do with any attachment.

Some email clients show you attachments as if they belong to the body in case it's a jpg-picture or if it's a html file.
But this is dangerous and not standard.

So if you want to send an email with html appearance you have to format your normal body text with the necessary html tags.
As attachments you may whatever you want.

I hope my explanation was not to complicated.
If yes, ask me again.

Regards,
Detlef

Posted: Fri Jul 06, 2007 5:20 pm
by yury
Hi Detlef,

thank you for explanation, very usefull...

do you have any example about message text formated with html tags what works with MS OutLook Express (TMail class invoke OE) ?

best regards and thank you again

Posted: Fri Jul 06, 2007 6:59 pm
by Detlef Hoefner
Hi Yuri,

i don't have Outlook.
But you should use something like the following example:

Code: Select all

LOCAL cMessage := "<HTML>"                                                                   + CRLF +;
                  "<HEAD>"                                                                   + CRLF +;
                  '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">' + CRLF +;
                  "</HEAD>"                                                                  + CRLF +;
                  "<BODY>"                                                                   + CRLF +;
                  "<p>Here a paragraph</p>"                                                  + CRLF +;
                  "<p>"                                                                      + CRLF +;                 
                  '  <table border="1" cellpadding="2" cellspacing="2">'                     + CRLF +;
                  "    <tr>"                                                                 + CRLF +;
                  "      <th>Val</th>"                                                       + CRLF +;
                  "      <th>Val * 100</th>"                                                 + CRLF +;
                  "    </tr>"                                                                + CRLF 

            for n := 1 to 12
               cMessage += "    <tr>" + CRLF +;
                           "      <td> " + str( n      , 2, 0 ) + "</td>"+ CRLF +;
                           "      <td> " + str( n * 100, 4, 0 ) + "</td>"+ CRLF +;
                           "    </tr>"                                   + CRLF
            next

            cMessage += "  </table>"        + CRLF +;
                        "<br><br>  "        + CRLF +;
                        "Normal Text here"  + CRLF +;
                        "</BODY>"           + CRLF +;
                        "</HTML>"


   DEFINE MAIL oMail;
      SUBJECT  cSubject;
      TEXT     cMessage

   oMail:aRecipients := aRecip
   oMail:aFiles      := aAttach

   ACTIVATE MAIL oMail

   oMail:End()
But it may be the recipient doesn't see the mail as html-formatted.
This depends on the settings of his email reader.

I hope this helps, otherwise ask me again.

Regards,
Detlef

Posted: Fri Jul 06, 2007 8:04 pm
by yury
Hi Detlef,

I will test your example and post results here...

Thanks you for help and attention

Best Regards