Jump to content
Fivewin Brasil

E-Mail não envia, mas envia antes


Theotokos

Recommended Posts

Usando uma rotina com CDO, consegui que aparecesse o erro...

só que dá esse erro com qualquer e-mail que eu tente.... tentei gmail, hotmail, bol,... tentei as portas 25, 465, 587 em todos eles... sempre a mesma msg


Fala ENVIo de EMAIL
Error: 1001;
SubC : 3;
OSCode : 0;
SubSystem: CDO.Message;
Operation: SEND;
Filename:;
Args:;
Mensagem: DISP_E_MEMBERNOTFOUND;

 

Link to comment
Share on other sites

São do Harbour, 

o hb_processOpen vc pode trocar por um Shellexecute algo assim, mas com parametro pra não aparecer q esta rodando, tipo rodar se aparecer janela.

o hb_Base64Encode ... essa aki não sei como seria em xHarbour, esses tempos acho q o João ajudou alguém com um assunto semelhante, talvez ele saiba.

 

oi... tentei executar esta rotina que vc passou, alias vlw muito obgdo por compartilhar.... mas esta dando como unresolved:

hb_Base64encode

hb_processOpen

Esta funções são do xHarbour mesmo ou do Harbour? se é do harbour tem algum similar no xharbour?

 

Link to comment
Share on other sites

a rotina é essa:

		oEmail 		 	  := hbNFeEmail()
		*
		oEmail:aFiles 	  := { AllTrim(cFile) }
		oEmail:aTo 	 	  := { AllTrim(cTo) }
		oEmail:cSubject  := cSubject
		oEmail:cMsgTexto := cBody
		oEmail:cMsgHTML  := nil
		oEmail:cServerIP := AllTrim(cServer)
		oEmail:cFrom     := AllTrim(cFrom)
		oEmail:cUser     := AllTrim(cUsuaID)
		oEmail:cPass     := AllTrim(cPassword)
		oEmail:nPortSMTP := nPort
		oEmail:lConf     := .F.
		oEmail:lSSL      := .T.
		oEmail:lAut      := .T.
		*
        aRetorno 		 := oEmail:execute()
        oEmail 		 := Nil
   	*
        IF aRetorno['OK'] == .F.
           ? aRetorno['MsgErro']
        ELSE
           ? 'Enviou'
        ENDIF

e classe é:

* Funcoes e Classes Relativas a NFE (Envio de Email)                                               *
* Usado como Base o Projeto Open ACBR e Sites sobre XML, Certificados e Afins                      *
* Qualquer modificação deve ser reportada para Fernando Athayde para manter a sincronia do projeto *
* Fernando Athayde 28/08/2011 fernando_athayde@yahoo.com.br                                        *
****************************************************************************************************
#include "common.ch"
#include "hbclass.ch"
#ifndef __XHARBOUR__
   #include "hbwin.ch"
   #include "harupdf.ch"
   #include "hbzebra.ch"
   #include "hbcompat.ch"
#endif
#include "hbnfe.ch"

CLASS hbNFeEmail
   DATA ohbNFe

   DATA cSubject
   DATA cMsgTexto
   DATA cMsgHTML
   DATA cServerIP
   DATA cFrom
   DATA cUser
   DATA cPass
   DATA nPortSMTP
   DATA lConf
   DATA lSSL
   DATA lAut

   DATA aFiles
   DATA aTo
   DATA aCC
   DATA aBCC

   METHOD execute()
ENDCLASS

METHOD execute() CLASS hbNFeEmail
LOCAL aRetorno := hash(), oCfg, oMsg, oError, nITo, nIFiles, cArgs, cFileName, xa, cArg, retorno

   IF VALTYPE( ::aTo ) == "C"
      ::aTo := { ::aTo }
   ENDIF
   IF ::cSubject == Nil
      ::cSubject := ::ohbNFe:cEMail_Subject
   ENDIF
   IF ::cMsgTexto == Nil
      ::cMsgTexto := ::ohbNFe:cEMail_MsgTexto
   ENDIF
   /*IF ::cMsgHTML == Nil
      ::cMsgHTML := ::ohbNFe:cEMail_MsgHTML
   ENDIF*/
   IF ::cServerIP == Nil
      ::cServerIP := ::ohbNFe:cEMail_ServerIP
   ENDIF
   IF ::cFrom == Nil
      ::cFrom := ::ohbNFe:cEMail_From
   ENDIF
   IF ::cUser == Nil
      ::cUser := ::ohbNFe:cEMail_User
   ENDIF
   IF ::cPass == Nil
      ::cPass := ::ohbNFe:cEMail_Pass
   ENDIF
   IF ::nPortSMTP == Nil
      ::nPortSMTP := ::ohbNFe:nEMail_PortSMTP
   ENDIF
   IF ::lConf == Nil
      ::lConf := ::ohbNFe:lEMail_Conf
   ENDIF
   IF ::lConf = Nil
      ::lConf = .F.
   ENDIF
   IF ::lSSL == Nil
      ::lSSL := ::ohbNFe:lEMail_SSL
   ENDIF
   IF ::lSSL = Nil
      ::lSSL = .F.
   ENDIF
   IF ::lAut == Nil
      ::lAut := ::ohbNFe:lEMail_Aut
   ENDIF

   // preparar
   TRY
        oCfg := CreateObject( "CDO.Configuration" )
     WITH OBJECT oCfg:Fields
       :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver"      ):Value := ::cServerIP
       :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport"  ):Value := ::nPortSMTP
       :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing"       ):Value := 2
       :Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"):Value := ::lAut
       :Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl"      ):Value := ::lSSL
       :Item( "http://schemas.microsoft.com/cdo/configuration/sendusername"    ):Value := ALLTRIM(::cUser)
       :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword"    ):Value := ALLTRIM(::cPass)
*       :Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" ):Value := 30
       :Update()
     END WITH
   CATCH oError
       aRetorno[ "OK" ] = .F.
      aRetorno[ "MsgErro" ] := "Falha conexão com o smtp"+HB_OsNewLine()+ ;
                               "Error: "  + Transform(oError:GenCode, nil) + ";" +HB_OsNewLine()+ ;
                                  "SubC: "   + Transform(oError:SubCode, nil) + ";" +HB_OsNewLine()+ ;
                                  "OSCode: "  + Transform(oError:OsCode,  nil) + ";" +HB_OsNewLine()+ ;
                                  "SubSystem: " + Transform(oError:SubSystem, nil) + ";" +HB_OsNewLine()+ ;
                                  "Mensangem: " + oError:Description
      RETURN( aRetorno )
   END

   // enviar
   FOR nITo:=1 TO LEN( ::aTo )
         oMsg := CreateObject ( "CDO.Message" )
      WITH OBJECT oMsg
        :Configuration := oCfg
        :From := ::cFrom
        :To   := ::aTo[ nITo ]
        IF ::aCC <> Nil
           :Cc := ::aCC
        ELSE
             :Cc := ""
        ENDIF
        IF ::aBCC <> Nil
           :BCC := ::aBCC
        ELSE
             :BCC := ""
        ENDIF
        :Subject := ::cSubject
        IF !EMPTY( ::cMsgTexto )
           :TextBody = ::cMsgTexto
        ELSE
           :HTMLBody = ::cMsgHTML
        ENDIF
        FOR nIFiles := 1 TO LEN( ::aFiles )
           IF FILE( ALLTRIM(::aFiles[ nIFiles ]) )
              :AddAttachment(ALLTRIM(::aFiles[ nIFiles ]))
           ELSE
              aRetorno[ "OK" ] := .F.
              aRetorno[ "MsgErro" ] := 'Arquivo não encontrado: '+::aFiles[ nIFiles ]
              RETURN(aRetorno)
           ENDIF
        NEXT
        IF ::lConf=.T.
         :Fields( "urn:schemas:mailheader:disposition-notification-to" ):Value := ::cFrom
         :Fields:update()
        ENDIF
      END WITH
      TRY
        retorno := oMsg:Send()
      CATCH oError
          cFilename := ""
          IF oError:Filename<>NIL
             IF VALTYPE(oError:Filename) = "C"
                cFilename := oError:Filename
             ELSEIF VALTYPE(oError:Filename) = "N"
                cFilename := TRANSFORM(oError:Filename,Nil)
             ELSE
               cFilename := VALTYPE(oError:Filename)
             ENDIF
            ENDIF
          cArgs := ""
          IF oError:Args<>NIL
             IF VALTYPE(oError:Args) = "C"
                cArgs := oError:Args
             ELSEIF VALTYPE(oError:Args) = "N"
                cArgs := TRANSFORM(oError:Args,Nil)
             ELSEIF VALTYPE(oError:Args) = "A"
                FOR xA = 1 TO LEN(oError:Args)
                   cArg := ""
                   IF VALTYPE(oError:Args[xA])="C"
                      cArg := oError:Args[xA]
                   ELSEIF VALTYPE(oError:Args[xA])="N"
                      cArg := TRANSFORM(oError:Args[xA],Nil)
                   ELSE
                      cArg := "desc."+VALTYPE(oError:Args[xA])
                   ENDIF
                   cArgs += cArg+","
                NEXT
             ELSE
               cArgs := VALTYPE(oError:Args)
             ENDIF
            ENDIF
            aRetorno[ "MsgErro" ] := "FALHA ENVIO DE EMAIL "+HB_OsNewLine()+ ;
                                    "Error: "  + Transform(oError:GenCode, nil) + ";" +HB_OsNewLine()+ ;
                                      "SubC: "   + Transform(oError:SubCode, nil) + ";" +HB_OsNewLine()+ ;
                                      "OSCode: "  + Transform(oError:OsCode,  nil) + ";" +HB_OsNewLine()+ ;
                                      "SubSystem: " + IF(oError:SubSystem=NIL,"",oError:SubSystem) + ";" +HB_OsNewLine()+ ;
                                      "Operation: " + IF(oError:Operation=NIL,"",IF(ISCHARACTER(oError:Operation),oError:Operation,STR(oError:Operation))) + ";" +HB_OsNewLine()+ ;
                                      "Filename: " + cFilename + ";" +HB_OsNewLine()+ ;
                                      "Args: " + cArgs + ";" +HB_OsNewLine()+ ;
                                      "Mensangem: " + IF(oError:Description=NIL,"",oError:Description) + ";"
         #ifndef __XHARBOUR__
             aRetorno[ "MsgErro" ] += "WinOle: "+ win_oleErrorText()
         #endif
         aRetorno[ "OK" ] = .F.
         RETURN( aRetorno )
      END
    NEXT
    aRetorno[ "OK" ] = .T.
RETURN( aRetorno )

 

Link to comment
Share on other sites

 

oi... tentei executar esta rotina que vc passou, alias vlw muito obgdo por compartilhar.... mas esta dando como unresolved:

hb_Base64encode

hb_processOpen

Esta funções são do xHarbour mesmo ou do Harbour? se é do harbour tem algum similar no xharbour?

 

Segue a função correlata pra usar em xHarbour

HB_Base64( cString, LEN( cString ) )

 

Mas precisar inserir o código em C abaixo pra compilar junto pelo q vi


HB_FUNC( HB_BASE64 )
{
char * szItem = hb_parc( 1 );
int nLen = hb_parni( 2 );
char * szRet = szItem ? base64enc( szItem, nLen ) : NULL;
Link to comment
Share on other sites

 

Usando uma rotina com CDO, consegui que aparecesse o erro...

só que dá esse erro com qualquer e-mail que eu tente.... tentei gmail, hotmail, bol,... tentei as portas 25, 465, 587 em todos eles... sempre a mesma msg



Fala ENVIo de EMAIL
Error: 1001;
SubC : 3;
OSCode : 0;
SubSystem: CDO.Message;
Operation: SEND;
Filename:;
Args:;
Mensagem: DISP_E_MEMBERNOTFOUND;

 

 

Link to comment
Share on other sites

 

Segue Demo.PRG e tb video explicativo, espero q ajude! Abraço.

 

FUNCTION TesteForumFive
	LOCAL cLinha, aAnexos
altd()	

	cLinha := ""

	//-- Bloco de Configuração da Conta do Email
	cLinha += "|EMAILCONF"
		cLinha += "|"+ ALLTRIM('smtp.gmail.com')            // smtp-mail.outlook.com|"
		cLinha += "|"+ ALLTRIM('fivewintester@gmail.com')   // contadoemail@hotmail.com|"
		cLinha += "|"+ hb_Base64encode('MinhaSenha123') // senha da conta
		cLinha += "|"+ allstr(587)      // Porta Exemplo Gmail pode ser 587
		cLinha += "|2"                        // 1= Default 2= Secured TLS  3= SSL (Obs: Para Hotmail usar 2)
		cLinha += "|"+CRLF                    // Final da linha/bloco
    
	//-- Bloco do Destinatario e da Mensagem
		cLinha += "|MESSAGE"
			cLinha += "|Fivewin Tester <fivewintester@gmail.com>"   // Quem envia   exemplo: Zezinho da Silva <zezinho@taltal.com.br>        
			cLinha += "|fladimir_arroyo@yahoo.com.br"               // Destinatario exemplo: fulano@taltal.com.br
			cLinha += "|Detalhes dos Movimentos dos Caixas"         // Assunto      exemplo: Detalhes do Movimento dos Caixas
			cLinha += "|Email enviado pelo sistema"                 // Mensagem     exemplo: E-mail enviado pelo sistema
			cLinha += "|"+ CRLF                                          // Final da linha/bloco
        
	//-- Bloco de Anexos... caso tenha
	
	aAnexos := { 'd:\detalhedoscaixas.pdf' }
	
	IF len(aAnexos)>0
		FOR nI:=1 to len(aAnexos)
		cLinha += "|ATTACH"
		cLinha += "|"+ aAnexos[nI] // Caminho do anexo exemplo: C:\Documentos\Detalhe_do_Movimento_dos_Caixas.PDF
		cLinha += "|"+ CRLF
		NEXT            
	ENDIF
	cLinha += "|FIM" +CRLF     
	IF .NOT. File("email_100.txt")
		Memowrit("email_100.txt", cLinha)
	ENDIF
	inkey(0) // Pra conferir arquivo TXT criado
	Run WEnvMail.exe
	Alert('Fim da rotina')
	// fim da rotina
	

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...