General Help regarding HMG, Compilation, Linking, Samples
Moderator: Rathinagiri
hmgchang
Posts: 273 Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Post
by hmgchang » Fri May 30, 2014 4:04 am
Dear Masters,
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;
*****/
#include "hmg.ch"
REQUEST HB_GT_WIN_DEFAULT
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" )
*- msgDebug( oMail:hHeaders, oMail)
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()
SetMode( 25, 80)
? "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'
?
?
wait
RETURN
I try the code, compile successed but when i run it :
i get this :
Attachments
TipMMail_Error.JPG (16.58 KiB) Viewed 3187 times
Just Hmg It !
hmgchang
Posts: 273 Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Post
by hmgchang » Fri May 30, 2014 4:08 am
i try :
Code: Select all
msgDebug( oMail:hHeaders, oMail)
at line 41
then i get this :
Attachments
TipMMail_Error2.JPG (19.96 KiB) Viewed 3186 times
Just Hmg It !
huiyi_ch
Posts: 172 Joined: Sat May 21, 2016 5:27 am
Post
by huiyi_ch » Sat Mar 10, 2018 3:03 am
我运行了这个例子程序,也出现了同样的错误!
I ran this example program and there was the same error!
serge_girard
Posts: 3176 Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB 2 DBF
Location: Belgium
Contact:
Post
by serge_girard » Sat Mar 10, 2018 8:56 am
Maybe Edward can help?
Serge
There's nothing you can do that can't be done...
edk
Posts: 917 Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Post
by edk » Sat Mar 10, 2018 12:51 pm
Hi. In my opinion, the oMail object is incorrectly initialized. It should be oMail:=TipMail():New() then the error is not generated.
The result is a generated message file in eml format.
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;
*****/
#include "hmg.ch"
REQUEST HB_GT_WIN_DEFAULT
PROCEDURE MAIN( ... )
LOCAL oMail, cData, i, oAttach
LOCAL cFname, cFExt
IF PCount() == 0
Usage()
QUIT
ENDIF
oMail := TipMail():New()
* - msgDebug( oMail:hHeaders, oMail)
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 */
STRFILE( oMail:ToString() ,'message.eml')
RETURN
PROCEDURE Usage()
SetMode( 25, 80)
? "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'
?
?
wait
RETURN
Edward.
huiyi_ch
Posts: 172 Joined: Sat May 21, 2016 5:27 am
Post
by huiyi_ch » Mon Mar 12, 2018 12:22 pm
Thank you very much Edward.
程序运行正常,但是收不到邮件!
The program runs normally, but it doesn't get the mail! What's the reason?
edk
Posts: 917 Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Post
by edk » Mon Mar 12, 2018 1:31 pm
TipMail () is not strictly for sending messages, but only for creating a string of characters to which the message is composed. It is used, among others inside the hb_sendmail function. See the "message.eml" file that you created.
With TipMail () you can also read the individual components of the message we receive. But the very process of receiving or sending messages is not done by TipMail ().
Note that there are no declared definitions of smtp servers, ports or credentials necessary to send a message.
If you need to send messages try using CDO.Message:
http://hmgforum.com/viewtopic.php?p=51497#p51497
I use this method to send emails with attached any type of files without problems.