HBTIP

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
Roberto Lopez
HMG Founder
Posts: 3905
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 15 times
Been thanked: 140 times

Re: HBTIP

Post by Roberto Lopez » Sun Sep 28, 2008 7:11 pm

Roberto Lopez wrote: 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.
The bottom line is:

HBTIP allows to me to send an html message and to attach the images.

The problem is how to specify the 'cid' for attached images to create a link between these images and HTML message body referencing it.

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Roberto Lopez
HMG Founder
Posts: 3905
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 15 times
Been thanked: 140 times

Post by Roberto Lopez » Mon Sep 29, 2008 10:32 am

Carlos Britos wrote:Did you try with Mht files ( all in there ) instead of Htm ?
No, but I want to send a 'real' message (not an attached file with the message).

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
mol
Posts: 2991
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 161 times
Been thanked: 87 times
Contact:

Post by mol » Thu Jan 14, 2010 9:01 am

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. :(

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

I wanna refresh this topic.
I want to send mail from my application, when error occurs.
But - I can't find, where to define servers in this pattern.
Did you test it?
Marek

User avatar
mol
Posts: 2991
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 161 times
Been thanked: 87 times
Contact:

Post by mol » Thu Jan 14, 2010 10:56 am

Browsing harbour sources, I found function HB_SendMail, created by Victor Szakats, but I can't send any mail...
Here is definition of parameters of this function.
Could anybody test it with own server settings?

Code: Select all

FUNCTION hb_SendMail( cServer, nPort, cFrom, xTo, xCC, xBCC, cBody, cSubject, aFiles, cUser, cPass, cPopServer, nPriority, lRead, bTrace, lPopAuth, lNoAuth, nTimeOut, cReplyTo, lTLS, cSMTPPass, cCharset, cEncoding )
   /*
   cServer    -> Required. IP or domain name of the mail server
   nPort      -> Optional. Port used my email server
   cFrom      -> Required. Email address of the sender
   xTo        -> Required. Character string or array of email addresses to send the email to
   xCC        -> Optional. Character string or array of email adresses for CC (Carbon Copy)
   xBCC       -> Optional. Character string or array of email adresses for BCC (Blind Carbon Copy)
   cBody      -> Optional. The body message of the email as text, or the filename of the HTML message to send.
   cSubject   -> Optional. Subject of the sending email
   aFiles     -> Optional. Array of attachments to the email to send
   cUser      -> Required. User name for the POP3 server
   cPass      -> Required. Password for cUser
   cPopServer -> Required. POP3 server name or address
   nPriority  -> Optional. Email priority: 1=High, 3=Normal (Standard), 5=Low
   lRead      -> Optional. If set to .T., a confirmation request is send. Standard setting is .F.
   bTrace     -> Optional. If set to .T., a log file is created (smtp-<nNr>.log). Standard setting is NIL.
                           If a block is passed, it will be called for each log event with the message a string, no param on session close.
   lPopAuth   -> Optional. Do POP3 authentication before sending mail.
   lNoAuth    -> Optional. Disable Autentication methods
   nTimeOut   -> Optional. Number os ms to wait default 20000 (20s)
   cReplyTo   -> Optional.
   */ 

User avatar
Alex Gustow
Posts: 290
Joined: Thu Dec 04, 2008 1:05 pm
Location: Yekaterinburg, Russia
Contact:

Post by Alex Gustow » Thu Jan 14, 2010 3:44 pm

Hi Marek!
I haven't time [yet! :( sorry - too much work] to write (as I wrote) good example about recieving and sending mails.

Here's simple examples [from "xHarbour Language Reference Guide" -> "xHarbour Reference Documentation" -> "Class Reference (textmode)" -> "TipMail()"]:

Incoming eMails:

Code: Select all

// The example outlines the steps required for retrieving all
// eMails from a POP mail server and how to decompose
// incoming mail messages.

   PROCEDURE Main
      LOCAL oPop, oPart, aParts, oTIpMail, aEmails, i

      oPop := TIpClientPop():new( "pop://mailaccount:password@pop.server.com" )

      IF .NOT. oPop:open()
         ? "Connection error:", oPop:lastErrorMessage()
         QUIT
      ELSE
         aEMails := oPop:retrieveAll()
         oPop:close()
      ENDIF

      FOR i:=1 TO Len( aEMails )
         oTIpMail := aEmails[i]
         ? oTIpMail:getFieldPart( "From" )
         ? oTIpMail:getFieldPart( "Subject" )

         IF oTIpMail:isMultiPart()
            // Retrieve all parts of a multipart message
            aParts := oTIpMail:getMultiParts()

            FOR EACH oPart IN aParts
               IF .NOT. Empty( oPart:getFileName() )
                  // This is a file attachment. Store it in the TMP folder.
                  IF oPart:detachFile( "C:\tmp\" )
                     ? "File written: C:\tmp\" + oPart:getFileName()
                  ENDIF
               ELSE
                  ? oPart:getBody()
               ENDIF
            NEXT
         ELSE
            // simple mail message
            ? oTIpMail:getBody()
         ENDIF
      NEXT

   RETURN
Outgoing eMails:

Code: Select all

// The example outlines the steps required for composing an eMail
// and sending it to an SMTP mail server.

   PROCEDURE Main
      LOCAL oSmtp, oEMail
      LOCAL cSmtpUrl
      LOCAL cSubject, cFrom, cTo, cBody, cFile

      // preparing data for eMail
      cSmtpUrl := "smtp://mailaccount:password@smtp.server.com"
      cSubject := "Testing eMail"
      cFrom    := "MyName@Mail.server.com"
      cTo      := "YourName@another.server.com"
      cFile    := "File_Attachment.zip"
      cBody    := "This is a test mail sent at: " + DtoC(Date()) + " " + Time()

      // preparing eMail object
      oEMail   := TIpMail():new()
      oEMail:setHeader( cSubject, cFrom, cTo )
      oEMail:setBody( cBody )
      oEMail:attachFile( cFile )

      // preparing SMTP object
      oSmtp := TIpClientSmtp():new( cSmtpUrl )

      // sending data via internet connection
      IF oSmtp:open()
         oSmtp:sendMail( oEMail )
         oSmtp:close()
         ? "Mail sent"
      ELSE
         ? "Error:", oSmtp:lastErrorMessage()
      ENDIF
   RETURN
About HB_SendMail: I use it - here's very simple example:

Code: Select all

    cToSend := "gugu@miac.utk.ru"

    cBodySend := "Hi there!" + CRLF + ;
    "This is a text of mail (body)" + CRLF + CRLF + ;
    "       Sincerely yours,     Alex"

    lRezSend := ;
    Hb_SendMail( ;
      "26.186.253.164", ;                     // SMTP server (IP or DNS-name)
      25, ;                                   // SMTP port
      "fromme@miac.utk.ru", ;              // cFrom
      cToSend, ;                              // aTo: string or array of strings
      , , ;                                   // aCC, aBCC
      cBodySend, ;                            // cBody
      "=== This is Subject! ===", ;  // cSubject
      , ;                                     // aFiles (array of attachments - if you need)
      "gritest", ;                          // cUser
      "gritest", ;                          // cPass
      "26.186.253.164", ;                     // POP3 server
      3, ;                                    // priority (3 = Normal)
      .F., .F., ;                             // no lRead, no lTrace,
      .T., .F., ;                             // yes lPopAuth, no autentication
      500, ;                // timeout 0.5 sec (default 20000 = 20 sec )
      "" ;                                    // cReplyTo
      )

I use it in console app. Compile file is:

Code: Select all

call c:\MiniGUI\batch\compile.bat test32 /x /c /l tip /l gtwin 
Maybe it helps?

User avatar
mol
Posts: 2991
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 161 times
Been thanked: 87 times
Contact:

Post by mol » Fri Jan 15, 2010 6:37 am

thanks Alex!
Yesterday, I was testing hp_sendmail and it worked with intranet exchange server, but, when I try it with public servers - it doesn't work.
I've installed packet sniffer to watch transmission and saw some errors messages sent from public smtp server.
I'll try again during weekend..

Many thanks!
Marek

hkrasser
Posts: 16
Joined: Fri Jul 10, 2009 12:08 pm
Location: Austria

Post by hkrasser » Thu Jan 28, 2010 2:08 pm

Hello Marek!
You postet a lot time ago - I tryed the same way:
lRetVal:=HB_SendMail( cServer,nPort , cFrom, aTo, , , cBody, cSubject, aFiles, cUser, cPass, cPopServer, , ,.T. )

Can You tell me what's the problem please?

Most times lRetVal = .T. but only few mails where sent, though there is always
>> 235 Authentication succeeded <<.

***************************************************************
This works:
20100128-14:33:51 :INETRECVLINE( <pointer>, , 512 )
>> 235 Authentication succeeded <<

20100128-14:33:51 :INETERRORCODE( <pointer> )
>> 0 <<

20100128-14:33:51 :INETSENDALL( <pointer>, 33, MAIL FROM: <hkrasser@utanet.at> )
>> 33 <<

20100128-14:33:51 :INETRECVLINE( <pointer>, , 512 )
>> 250 OK <<

20100128-14:33:51 :INETERRORCODE( <pointer> )
>> 0 <<

20100128-14:33:51 :INETSENDALL( <pointer>, 31, RCPT TO: <hkrasser@utanet.at> )
>> 31 <<

20100128-14:33:51 :INETRECVLINE( <pointer>, , 512 )
>> 250 Accepted <<

20100128-14:33:51 :INETERRORCODE( <pointer> )
>> 0 <<

20100128-14:33:51 :INETSENDALL( <pointer>, 6, DATA )
>> 6 <<

20100128-14:33:51 :INETRECVLINE( <pointer>, , 512 )
>> 354 Enter message, ending with "." on a line by itself <<

20100128-14:33:51 :INETERRORCODE( <pointer> )
>> 0 <<

20100128-14:33:51 :INETSENDALL( <pointer>, 386, Date: Thu, 28 Jan 2010 14:33:50 +0000From: hkrasser@utanet.atTo: hkrasser@utanet.atSubject: Test-Mail HarbourMime-Version:1.0Content-Type: multipart/mixed; Boundary="=_0DREPHDICDJQGIWVBR_TIP_28.01.2010_143351"--=_0DREPHDICDJQGIWVBR_TIP_28.01.2010_143351Content-transfer-encoding: as-isDas ist der Body-Text des Mails--=_0DREPHDICDJQGIWVBR_TIP_28.01.2010_143351-- )
>> 386 <<

20100128-14:33:51 :INETSENDALL( <pointer>, 5, . )
>> 5 <<

20100128-14:33:51 :INETRECVLINE( <pointer>, , 512 )
>> 250 OK id=1NaUUq-0000XK-4L <<

20100128-14:33:51 :INETERRORCODE( <pointer> )
>> 0 <<

***********************************************************************************
This does not work:

20100128-14:36:47 :INETRECVLINE( <pointer>, , 512 )
>> 235 Authentication succeeded <<

20100128-14:36:47 :INETERRORCODE( <pointer> )
>> 0 <<

20100128-14:36:47 :INETSENDALL( <pointer>, 33, MAIL FROM: <hkrasser@utanet.at> )
>> 33 <<

20100128-14:36:47 :INETRECVLINE( <pointer>, , 512 )
>> NIL <<

20100128-14:36:47 :INETERRORCODE( <pointer> )
>> -1 <<

20100128-14:36:47 :INETSENDALL( <pointer>, 5, . )
>> 5 <<

20100128-14:36:48 :INETRECVLINE( <pointer>, , 512 )
>> NIL <<

20100128-14:36:48 :INETERRORCODE( <pointer> )
>> -1 <<


Hans from Austria

User avatar
mol
Posts: 2991
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 161 times
Been thanked: 87 times
Contact:

Post by mol » Wed Oct 17, 2012 10:47 am

Hi guys!
I'm refreshing this topic, because I needo to send e-mails via IMAP server. I was sending alerts from my system via SMTP server and everything was OK, but, corporation changed security policies now, and only way is to use IMAP.

So, I have a question:
Has anybody working sample with sending mails via IMAP server?

Best regards, Marek

User avatar
danielmaximiliano
Posts: 2078
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Has thanked: 114 times
Been thanked: 15 times
Contact:

Post by danielmaximiliano » Wed Oct 17, 2012 1:04 pm

mol wrote:Hi guys!
I'm refreshing this topic, because I needo to send e-mails via IMAP server. I was sending alerts from my system via SMTP server and everything was OK, but, corporation changed security policies now, and only way is to use IMAP.

So, I have a question:
Has anybody working sample with sending mails via IMAP server?

Best regards, Marek
Hello Marek, your server is IMAP or IMAPS?.

the second use SSL, in this case you have to install openssl and recompile the library HBTIP.
but look CDOSYS in forum and use the sample.
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`.HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. : +54901169026142
Telegram Name : DaNiElMaXiMiLiAnO

User avatar
mol
Posts: 2991
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 161 times
Been thanked: 87 times
Contact:

Post by mol » Wed Oct 17, 2012 5:28 pm

thx, I'll try tomorrow

Post Reply