Page 1 of 3

HBTIP

Posted: Sat Sep 27, 2008 12:26 pm
by Roberto Lopez
Hi All,

Does any know if is possible to send html email with image embedded using HBTIP Harbour contribution library?

TIA.

Regards,

Roberto.

Re: HBTIP

Posted: Sat Sep 27, 2008 5:25 pm
by esgici
Hi all

This is a tantalus-torture (*) :!:

We have a huge treasure under our hands and we can't utilize in satisfy it because lack of documentation :cry:

Regards

(*) Read definition

--

esgici

Re: HBTIP

Posted: Sat Sep 27, 2008 6:29 pm
by Roberto Lopez
esgici wrote:Hi all

This is a tantalus-torture (*) :!:

We have a huge treasure under our hands and we can't utilize in satisfy it because lack of documentation :cry:

Regards

(*) Read definition

--

esgici
Tantalus story is terrible... perhaps this is a little less 'dramatic' :)

Regards,

Roberto.

Re: HBTIP

Posted: Sat Sep 27, 2008 10:03 pm
by esgici
Roberto Lopez wrote:Tantalus story is terrible... perhaps this is a little less 'dramatic' :)
You are right.

But similarity isn't quite painful ?

Regards

--

esgici

Re: HBTIP

Posted: Sun Sep 28, 2008 12:59 am
by Rathinagiri
In our language, there is a saying, "There is no peeled banana." :(

Re: HBTIP

Posted: Sun Sep 28, 2008 1:54 am
by Rathinagiri
I think we have to use -m option in the following sample given in tipmmail.prg. I am sure, you might have checked this already. I had not compiled and tested though. :(

Code: Select all

/*
 * $Id: tipmmail.prg 8751 2008-06-19 00:02:50Z vszakats $
 */

/******************************************
* TIP test
* Mail - reading and writing multipart mails
*
* Creating a mail message.
* This will create a valid mail message, using
* the set of files given in the command line.
*
* Usage:
* testmmail [options] attachment1, attachment2...
*  options:
*    -h              Help
*    -f "from"       Set "mail from" field
*    -t "to"         Set "mail to" field
*    -s "subject"    Set mail subject
*    -b "body"       Set mail body (or message)
*    -m "bodyfile"   Set mail body using a file
*
*
* This test writes data to standard output, and is
* compiled only under GTCGI;
*****/

PROCEDURE MAIN( ... )
   LOCAL oMail, cData, i, oAttach
   LOCAL cFname, cFExt

   IF PCount() == 0
      Usage()
      QUIT
   ENDIF

   oMail := TipMail( "This is the body of the mail" )
   oMail:hHeaders[ "Content-Type" ] := "text/plain; charset=iso8851"
   oMail:hHeaders[ "Date" ]  := Tip_Timestamp()

   i := 1
   DO WHILE i < PCount()
      cData := hb_PValue(i)

      IF lower( cData ) == "-h"
         Usage()
         QUIT
      ENDIF

      IF lower( cData ) == "-f"
         i++
         cData := hb_PValue(i)
         IF cData != NIL
            oMail:hHeaders[ "From" ] := cData
         ENDIF
      ELSEIF lower( cData ) == "-t"
         i++
         cData := hb_PValue(i)
         IF cData != NIL
            oMail:hHeaders[ "To" ] := cData
         ENDIF
      ELSEIF lower( cData ) == "-s"
         i++
         cData := hb_PValue(i)
         IF cData != NIL
            oMail:hHeaders[ "Subject" ] := cData
         ENDIF
      ELSEIF lower( cData ) == "-b"
         i++
         cData := hb_PValue(i)
         IF cData != NIL
            oMail:SetBody( cData + e"\r\n" )
         ENDIF
      ELSEIF lower( cData ) == "-m"
         i++
         cData := hb_PValue(i)
         IF cData != NIL
            cData := Memoread( cData )
            IF Empty(cData)
               ? "FATAL: Can't read", hb_PValue(i)
               QUIT
            ENDIF
            oMail:SetBody( cData + e"\r\n")
         ENDIF
      ELSE  // it is an attachment file
         cData := Memoread( cData )
         IF Empty(cData)
            ? "FATAL: Can't read attachment", hb_PValue(i)
            QUIT
         ENDIF
         oAttach := TipMail():New()

         oAttach:SetEncoder( "base64" )
         //TODO: mime type magic auto-finder
         HB_FNameSplit( hb_PValue(i),,@cFname, @cFext )
         // Some EMAIL readers use Content-Type to check for filename
         oAttach:hHeaders[ "Content-Type" ] := ;
               "application/X-TIP-Attachment; filename=";
               + cFname + cFext
         // But usually, original filename is set here
         oAttach:hHeaders[ "Content-Disposition" ] := ;
               "attachment; filename=" + cFname + cFext
         oAttach:SetBody( cData )

         oMail:Attach( oAttach )
      ENDIF

      i++
   ENDDO

   /* Writing stream */
   FWrite( 1, oMail:ToString() )
RETURN


PROCEDURE Usage()
   ? "Usage:"
   ? "testmmail [options] attachment1, attachment2..."
   ? "  options:"
   ? "    -h              Help"
   ? '    -f "from"       Set "mail from" field'
   ? '    -t "to"         Set "mail to" field'
   ? '    -s "subject"    Set mail subject'
   ? '    -b "body"       Set mail body (or message)'
   ? '    -m "bodyfile"   Set mail body using a file'
   ?
   ?
RETURN

Re: HBTIP

Posted: Sun Sep 28, 2008 12:22 pm
by Roberto Lopez
rathinagiri wrote:I think we have to use -m option in the following sample given in tipmmail.prg. I am sure, you might have checked this already. I had not compiled and tested though. :(
Yes, but it does not provide information about how the connection is established.

I've found in hbtip files 'sendmail.prg' it has a function 'hb_sendmail' and I've made it work.

It allows to send html messages and you can attach files, but the problem is how to relate an attached images with html body.

Regards,

Roberto.

Re: HBTIP

Posted: Sun Sep 28, 2008 3:50 pm
by Carlos Britos
Did you try with Mht files ( all in there ) instead of Htm ?

Re: HBTIP

Posted: Sun Sep 28, 2008 4:43 pm
by Rathinagiri
This is from another forum. I don't know if it helps you or not.

how to embed image in HTML ?

Depends on how you're trying to do it, but your mail composing program will need a way to send multipart/mime messages. The image is converted to base64 and the data sent by the mailer looks something like:

Code: Select all

From: foo1atbar.net
To: foo2atbar.net
Subject: A simple example
Mime-Version: 1.0
Content-Type: multipart/related; boundary="boundary-example"; type="text/html"

--boundary-example
Content-Type: text/html; charset="US-ASCII"

... text of the HTML document, which might contain a URI
referencing a resource in another body part, for example
through a statement such as:
<IMG SRC="cid:foo4atfoo1atbar.net" ALT="IETF logo">

--boundary-example
Content-Location: CID:somethingatelse ; this header is disregarded
Content-ID: <foo4atfoo1atbar.net>
Content-Type: IMAGE/GIF
Content-Transfer-Encoding: BASE64

R0lGODlhGAGgAPEAAP/////ZRaCgoAAAACH+PUNv
cHlyaWdodCAoQykgMTk5LiBVbmF1dGhvcml6ZWQgZHV
wbGljYXRpb24gcHJvaGliaXRlZC4A etc...

--boundary-example--

Note how the HTML code in the first part includes <img src="cid:foo.." the CID means that it's to look in another part of the multipart message.

From: http://www.htmlcodetutorial.com/help/sutra42473.html

Re: HBTIP

Posted: Sun Sep 28, 2008 6:27 pm
by Roberto Lopez
rathinagiri wrote:This is from another forum. I don't know if it helps you or not.

how to embed image in HTML ?

Depends on how you're trying to do it, but your mail composing program will need a way to send multipart/mime messages. The image is converted to base64 and the data sent by the mailer looks something like:

Code: Select all

From: foo1atbar.net
To: foo2atbar.net
Subject: A simple example
Mime-Version: 1.0
Content-Type: multipart/related; boundary="boundary-example"; type="text/html"

--boundary-example
Content-Type: text/html; charset="US-ASCII"

... text of the HTML document, which might contain a URI
referencing a resource in another body part, for example
through a statement such as:
<IMG SRC="cid:foo4atfoo1atbar.net" ALT="IETF logo">

--boundary-example
Content-Location: CID:somethingatelse ; this header is disregarded
Content-ID: <foo4atfoo1atbar.net>
Content-Type: IMAGE/GIF
Content-Transfer-Encoding: BASE64

R0lGODlhGAGgAPEAAP/////ZRaCgoAAAACH+PUNv
cHlyaWdodCAoQykgMTk5LiBVbmF1dGhvcml6ZWQgZHV
wbGljYXRpb24gcHJvaGliaXRlZC4A etc...

--boundary-example--

Note how the HTML code in the first part includes <img src="cid:foo.." the CID means that it's to look in another part of the multipart message.

From: http://www.htmlcodetutorial.com/help/sutra42473.html
Thanks, it appears to be useful.

I'll review it.

Anyway, I've solved the problem via the 'hard way'.

I've created the message using Outlook, saving it in '.eml' format, and then programmatically doing changes required in that file for different situations.

Very hard, but works...

Regards,

Roberto.