FW App sending email but pc has no email client

FW App sending email but pc has no email client

Postby fraxzi » Tue Mar 03, 2015 1:51 am

Dear All,

Can a FW App able to send email but the user's PC has no SMTP?

Thanks.
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: FW App sending email but pc has no email client

Postby Marcelo Via Giglio » Tue Mar 03, 2015 2:24 am

fraxzi,

I am trying to do the same, I tryed with this sample http://forums.fivetechsupport.com/viewtopic.php?f=3&t=26316&hilit=email+cdo but I get the next error


Application
===========
Path and name: D:\b\mio\email\email.exe (32 bits)
Size: 1,744,384 bytes
Compiler version: xHarbour build 1.2.1 Intl. (SimpLex) (Rev. 6406)
FiveWin Version: FWHX 12.03
Windows version: 6.1, Build 7601 Service Pack 1

Time from start: 0 hours 0 mins 1 secs
Error occurred at: 03/02/15, 22:18:33
Error description: Error CDO.Message/3 DISP_E_MEMBERNOTFOUND: SEND
Args:

Stack Calls
===========
Called from: source\rtl\win32ole.prg => TOLEAUTO:SEND( 0 )
Called from: email.prg => MAIN( 27 )



maybe you have luck, in this case please share your experience with us, or if other friend in the forum have a working sample can publish it

Thanks

saludos

Marcelo Vía
Marcelo Via Giglio
 
Posts: 1069
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: FW App sending email but pc has no email client

Postby hua » Tue Mar 03, 2015 2:35 am

Can try looking into Blat
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: FW App sending email but pc has no email client

Postby reinaldocrespo » Tue Mar 03, 2015 11:12 pm

Frances;

Hi. You don't need an SMTP server on the computer or workstation. You will need an SMTP server (or some sort of mail server) on some server somewhere. Your (x)harbour app is working as a client to the server. I usually use the mail server where the customer has his domain hosted (for example dreamhost). You could also use gmail. I have moved from TSMTP fw class to CDO. Here is sample code:

Code: Select all  Expand view  RUN
//-------------------------------------------------------------------------------
METHOD SendUsingCDO() CLASS TMpMail
   LOCAL oEmailMsg, oErr
   LOCAL cSchema := "http://schemas.microsoft.com/cdo/configuration/"
   LOCAL cFile
   LOCAL lFailed := .F.

   ::cCopyTo := ""
   IF ::aCopyTo # NIL .AND. !EMPTY( ::aCopyTo )
      AEVAL( ::aCopyTo, { |e| ::cCopyTo+= ALLTRIM( e ) + ";" } )
   ENDIF

   IF !EMPTY( ::aSendTo ) .AND. LEN( ::aSendTo ) > 0  //.AND. EMPTY( ::cEMailAddress )
      ::cEMailAddress := ""
      AEVAL( ::aSendTo, { |e| ::cEMailAddress += ALLTRIM( e ) + ";" } )
   ENDIF
   ::cEMailAddress := LEFT( ::cEMailAddress, LEN( ::cEMailAddress )-1 )
   ::logDebugInfo()
   
   TRY
   
      oEmailMsg  := CREATEOBJECT ( "CDO.Message" )

      WITH OBJECT oEmailMsg
     
         :From     := ALLTRIM( ::cFromEMail )
         :To       := ::cEMailAddress
         :CC       := ::cCopyTo
         :BCC      := ""
         :Subject  := ALLTRIM( ::cSubject )
         :TextBody := ::cBody

         FOR EACH cFile IN ::aAttachedfiles
            :AddAttachment( ALLTRIM( cFile ) )
         NEXT

         WITH OBJECT :configuration:Fields

            :Item( cSchema + "smtpserver" ):Value       := ALLTRIM( ::cSmtpHost )
            :Item( cSchema + "smtpserverport" ):Value   := ::nSmtpPort
            :Item( cSchema + "sendusing" ):Value        := iif( ::isRemoteSMTP, 2, 1 )
            :Item( cSchema + "smtpauthenticate" ):Value := ::lSMTPAuth
            :Item( cSchema + "smtpusessl" ):Value       := ::lUseSSL
            :Item( cSchema + "sendusername" ):Value     := ALLTRIM( ::cUserName )
            :Item( cSchema + "sendpassword" ):Value     := ALLTRIM( ::cUserPasswrd )
            :Item( cSchema + "smtpconnectiontimeout"):Value := ::nTimeOut

            :Update()

         END WITH        

         :Send()

      END

   CATCH oErr
      WriteErrorLog( oErr )
      lFailed := .t.

      IF ::bSMTPFail != NIL ;EVAL( ::bSMTPFail, SELF )   ;ENDIF
     
   END

   IF ::bSMTPDone != NIL  ; EVAL( ::bSMTPDone, SELF )  ;ENDIF

RETURN lFailed

 


To use Gmail you must turn ::lUseSSL as well as ::lSMTPAuth and ::isRemoteSMTP to .T. and use port 587 or 465. Try it. It is working great for me.

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: FW App sending email but pc has no email client

Postby reinaldocrespo » Tue Mar 03, 2015 11:15 pm

Marcelo;

Hola, siempre es grato saber de ti. Espero sigas bien.

You always get this same "generic" error when any of the CDO parameters is not right (or just perfect). Try my code above. Make sure you have all the correct parameters aligned. If it doesn't work just write a self-contained reduced fw sample that we can share and work together. Let me know how it works for you. I'll be glad to help.

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: FW App sending email but pc has no email client

Postby fraxzi » Wed Mar 04, 2015 5:10 am

Reinaldo,

Thanks so much this could save me tons of headaches..

can you please explain more.. like
Code: Select all  Expand view  RUN
LOCAL cSchema := "http://schemas.microsoft.com/cdo/configuration/"
what is it for..


Thanks.
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: FW App sending email but pc has no email client

Postby fraxzi » Wed Mar 04, 2015 6:39 am

I got this error:

Image

What library do I need to add?
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: FW App sending email but pc has no email client

Postby fraxzi » Wed Mar 04, 2015 6:51 am

Dear All,

BTW, the FW App installed in PC without internet access, no email client installed. Just the FW App but with access to LAN with internal SMTP.

Thanks for the help.
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: FW App sending email but pc has no email client

Postby Marcelo Via Giglio » Wed Mar 04, 2015 12:00 pm

Hola Reinaldo,

in base a your code, I made this simple sample

Code: Select all  Expand view  RUN
#include "fivewin.ch"

FUNCTION main()
   LOCAL oEmailMsg, oErr
   LOCAL cSchema := "http://schemas.microsoft.com/cdo/configuration/"
   LOCAL cFile
   LOCAL lFailed := .F.
   
      oEmailMsg  := CREATEOBJECT ( "CDO.Message" )

      WITH OBJECT oEmailMsg
     
         :From     := "cartekbackup@gmail.com"
         :To       := "marcelo.via@gmail.com"
         :CC       := ""
         :BCC      := ""
         :Subject  := "TEST"
         :TextBody := "CUERPITO"

         WITH OBJECT :configuration:Fields

            :Item( cSchema + "smtpserver" ):Value           := "smtp.google.com"
            :Item( cSchema + "smtpserverport" ):Value       := 465 //586
            :Item( cSchema + "sendusing" ):Value            := 2
            :Item( cSchema + "smtpauthenticate" ):Value     := .T.
            :Item( cSchema + "smtpusessl" ):Value           := .T.
            :Item( cSchema + "sendusername" ):Value         := "login"
            :Item( cSchema + "sendpassword" ):Value         := "password"
            :Item( cSchema + "smtpconnectiontimeout"):Value := 30

            :Update()

         END WITH        

         :Send()

      END

RETURN NIL


and I got the mentioned error message, I have right "login" and "password" I change the gmail account settings to low the enforcement authenticate method (suggested by gmail)

Reinaldo,

cuando tienes tiempo para tener una de esas emocionantes conferencias :-)

un abrazo

Marcelo
Marcelo Via Giglio
 
Posts: 1069
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: FW App sending email but pc has no email client

Postby reinaldocrespo » Wed Mar 04, 2015 9:30 pm

Frances / Marcelo;

I think the problem you are both having is the same. I took marcelo's code and only made these changes:

Code: Select all  Expand view  RUN

         :From     := "reinaldo.crespo@gmail.com"
...
         WITH OBJECT :configuration:Fields

            :Item( cSchema + "smtpserver" ):Value           := "smtp.gmail.com"
            :Item( cSchema + "sendusername" ):Value         := "reinaldo.crespo@gmail.com"
            :Item( cSchema + "sendpassword" ):Value         := "MySecretPassword"
...
 


It worked perfectly.

@Marcelo: notice you are using smtp.google.com which is not a valid url to any smtp server. Also, make sure the usename and password combination are valid. If you are using smtp.gmail.com then remember you will probably have to create an app specific password (https://security.google.com/settings/u/ ... ppasswords).

@Frances: if you are using a local SMTP server, then you probably don't need ssl. You could continue using fw Tsmtp class and validate username+password OR you could use CDO but first find out if your smtp server requires SSL connection and change "sendusing" value to 1. For the server's name make sure you use a DNS entry that resolves to the server's ip address. Again, with a local SMTP server I'd probably use FW TSMTP class where you have a lot more control over what's happening.

here is my code from he same class that uses TSMTP class to send emails:
Code: Select all  Expand view  RUN

//-------------------------------------------------------------------------------------
METHOD SendUsingSMTP() CLASS TMpMail
   LOCAL oMail,oErr
   LOCAL bEnd     := { || IF( oMail # NIL, oMail:End(), ), oMail := NIL }
   LOCAL aSendTo  := ::aSendTo

 
   IF EMPTY( aSendTo )  ;aSendTo := HB_ATOKENS( ::cEMailAddress, IIF( AT( ::cEMailAddress, ";" ) > 0, ";", "," ) ) ;ENDIF
   
   oMail := TSmtp():New( ::cIp, ::nSmtpPort, ::lSMTPAuth, ::cUserName, ::cUserPasswrd )
   oMail:lTxtAsAttach := .F.     // .T. forces text files as attachments, not inline
   oMail:cReplyTo := ::cFromEMail
   oMail:nGMT := TimeZone() //-5   // Atlantic Standard Time (GMT -05:00)

   oMail:oSocket:lDebug := ::lSMTPDebug
   oMail:oSocket:cLogFile := "smtp.log"
   oMail:nDelay := ::nTimeOut

   ::LogDebugInfo()

   oMail:bDone := { || IIF( ::bSMTPDone != NIL , EVAL( ::bSMTPDone, oMail ), ),;
            ;//AEVAL( oMail:aAttachments, { |e| ferase( e ) } ),;
            Logfile( "smtp.log", { "Done event fired" } ),;
            EVAL( bEnd ) }


   oMail:bFailure := { || ;
      IIF( oMail != Nil .AND. oMail:oSocket:lDebug, ;
         Logfile( oMail:oSocket:cLogFile, ;
               { "Failure to send email. Status = " + cValToChar( oMail:nStatus ) + CRLF + ;
                  oMail:cError + CRLF +;
                  "lAuth = " + cValToChar( oMail:lAuth ) + CRLF +;
                  "lDoAuth = " + cValToChar( oMail:lDoAuth ) + CRLF +;
                  "cUser = " + oMail:cUser + CRLF + ;
                  "cFrom = " + oMail:cFrom + CRLF + ;
                  "cPassword = " + oMail:cPassword } ), ),;
         IIF( ::bSMTPFail != NIL , EVAL( ::bSMTPFail, oMail ), ),;
         EVAL( bEnd ) }


   oMail:bConnecting   := { || iif( oMail:oSocket:lDebug,;
      logfile( oMail:oSocket:cLogFile, {"Connecting to SMTP server " + ::cIp } ), ) }

   oMail:bConnected   := { || iif( oMail:oSocket:lDebug, ;
      ( logfile( oMail:oSocket:cLogFile, { "Sending eMail Via " + ::cSmtpHost, oMail:cError } ),;
      logfile( oMail:oSocket:cLogFile, aSendTo ) ), ) }

   oMail:SendMail( ::cFromEMail ,   aSendTo, ::cBody, ::cSubject, ::aAttachedfiles, ::aCopyTo ,, .F.  )


RETURN NIL

 


Hope that helps.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: FW App sending email but pc has no email client

Postby Rick Lipkin » Wed Mar 04, 2015 9:39 pm

I think Reinaldo and I are on the same page .. I am using Gmail as my Smtp relay host ( just create a gmail account ) and this code works for me also.

Rick Lipkin
Code: Select all  Expand view  RUN

//---------------------------------------------
Function _SendMail(cSmtp_Host,nPort,lSsl,;
                           cSmtp_UserId,cSmtp_Password,cFrom,cTo,aCC,cSubject,cMessage,oDlg)

Local oEmailCfg,oErr,lFailed,oEmailMsg,cAddress,i

*msginfo( cSmtp_host )
*msginfo( nPort )
*msginfo( lssl )
*msginfo( cSmtp_UserId )
*msginfo( cSmtp_Password )
*msginfo( "Cfrom "+cFrom )
*msginfo( cTo )
*xbrowse(aCC)
*msginfo( cSubject )



SysReFresh()

// smtpauthenticate
// 0 cdoAnonymous Perform no authentication.
// 1 cdoBasic     Use the basic (clear text) authentication mechanism.
// 2 cdoNTLM      Use the NTLM authentication mechanism.

// sendusing
// Remote SMTP = 2, local = 1

If empty(aCC)
   cAddress := ""
Else
   For i = 1 to Len(aCC)
       If i = 1
          cAddress := aCC[i]
       Else
          cAddress := cAddress+","+aCC[i]
       Endif
    Next
Endif

lFailed := .f.
TRY
  oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
  WITH OBJECT oEmailCfg:Fields
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value       := cSmtp_Host
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value   := nPort
  :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value        := 2
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := 1
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value       := lSsl
  :Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value     := cSmtp_Userid
  :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value     := cSmtp_Password
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 15
  :Update()
  END WITH

CATCH oError
   MsgInfo( "Error in Configuration" )
END

oError := NIL
TRY
   oEmailMsg  := CREATEOBJECT ( "CDO.Message" )
   WITH OBJECT oEmailMsg
        :Configuration = oEmailCfg
        :From     := cFrom //"me@bogus.com"
        :To       := cTo
        :CC       := cAddress

    //  :CC       := ""
        :BCC      := ""
        :Subject  := cSubject
     // :MDNRequested = .T.       // request acknowledgement
        :TextBody := cMessage

        * for each cFile in ::aFiles
                *    :AddAttachment( cfile )
        * next
        :Fields:update()
        :Send()
     // ? "[ "+Time()+" ] Mail Sent :"+ ::email
   END
CATCH oError
      MsgINfo("Error in sending e-mail:"+  oError:Description )
      lFailed := .t.
END

oEmailCfg := NIL
oEmailMsg := NIL

oDlg:End()
SysRefresh()

Return(lFailed)
 
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: FW App sending email but pc has no email client

Postby Marcelo Via Giglio » Wed Mar 04, 2015 9:51 pm

Dear Reinaldo,

thanks very much, I can see my mistakes, the sample work ok

best regards

Marcelo
Marcelo Via Giglio
 
Posts: 1069
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 44 guests