Página 5 de 9

Email pelo Harbour

Enviado: 01 Abr 2015 20:25
por janio
Na sua função a porta eh 465 para gmail?

Janio

Email pelo Harbour

Enviado: 02 Abr 2015 16:03
por janio
Definitivamente, nao funciona!

Deve haver alguma coisa na sua função que não tem na do Rochinha. Algum pequeno detalhe!

Janio

Email pelo Harbour

Enviado: 02 Abr 2015 16:54
por janio
FUNCIONOUUUUU!

O problema não está na rotina, mas sim na configuração do seu email no google. Tem q entrar no email e ATIVAR a configuração para usar "Aplicativos menos seguros" no envio de email.

So isso. Frescuragi do gmail.

Janio

Email pelo Harbour

Enviado: 16 Jun 2015 20:48
por rubens
E não da para um de voces postarem essa rotina funcionando aqui para servir de exemplo... Tô precisando enviar xml e danfe nfe para o cliente....
Seria mais fácil se fosse nativo... do que usar programa externo...

Obrigado
Rubens

Email pelo Harbour

Enviado: 16 Jun 2015 21:04
por Itamar M. Lins Jr.
Ola!
De novo ?
Olhe ai!

Código: Selecionar todos

/* Copyright 2009 Viktor Szakats (vszakats.net/harbour) */

#require "hbssl"
#require "hbtip"

#if ! defined( __HBSCRIPT__HBSHELL )
REQUEST __HBEXTERN__HBSSL__
#endif

#include "simpleio.ch"

PROCEDURE Main( cFrom, cPassword, cTo, cHost )

   LOCAL nPort
   LOCAL lSTARTTLS := .F.

   IF ! tip_SSL()
      ? "Error: Requires SSL support"
      RETURN
   ENDIF

   hb_default( @cFrom    , "<from@example.net>" )
   hb_default( @cPassword, "password" )
   hb_default( @cTo      , "to@example.com" )
   hb_default( @cHost    , "localhost" )

   cHost := Lower( cHost )

   /* SMTPS works with SSL/TLS on port 465 and with STARTTLS
      on port 587. STARTTLS mode is fully automatic and require
      that SSL/TLS be disabled at first (it will be activated
      on request after STARTTLS command) */

   DO CASE
   CASE cHost == "apple" .OR. "@icloud.com" $ cFrom .OR. "@mac.com" $ cFrom .OR. "@me.com" $ cFrom
      cHost := "smtp.mail.me.com"; lSTARTTLS := .T.
   CASE cHost == "fastmail" .OR. "@fastmail.com" $ cFrom .OR. "@fastmail.fm" $ cFrom
      cHost := "mail.messagingengine.com"
   CASE cHost == "gmx.net" .OR. "@gmx.net" $ cFrom .OR. "@gmx.ch" $ cFrom .OR. "@gmx.de" $ cFrom
      cHost := "mail.gmx.net"; lSTARTTLS := .T.
   CASE cHost == "google" .OR. "@gmail.com" $ cFrom .OR. "@googlemail.com" $ cFrom
      cHost := "smtp.gmail.com"
   CASE cHost == "mail.ru" .OR. "@mail.ru" $ cFrom
      cHost := "smtp.mail.ru"
   CASE cHost == "netease" .OR. "@163.com" $ cFrom
      cHost := "smtp.163.com"
   CASE cHost == "office365"
      cHost := "smtp.office365.com"; lSTARTTLS := .T.
   CASE cHost == "outlook" .OR. "@outlook.com" $ cFrom .OR. "@hotmail.com" $ cFrom
      cHost := "smtp-mail.outlook.com"; lSTARTTLS := .T.
   CASE cHost == "sina" .OR. "@sina.com" $ cFrom
      cHost := "smtp.vip.sina.com"
   CASE cHost == "uol" .OR. "@uol.com.br" $ cFrom
      cHost := "smtps.uol.com.br"
   CASE cHost == "yahoo" .OR. "@yahoo.com" $ cFrom
      cHost := "smtp.mail.yahoo.com"
   CASE ":" $ cHost
      IF TUrl():New( cHost ):nPort != -1
         nPort := TUrl():New( cHost ):nPort
      ENDIF
      lSTARTTLS := ( nPort == 587 )
      cHost := TUrl():New( cHost ):cServer
   ENDCASE

   hb_default( @nPort, iif( lSTARTTLS, 587, 465 ) )

   ? "Host:", cHost, hb_ntos( nPort ), iif( lSTARTTLS, "(STARTTLS)", "" )

   ? tip_MailSend( ;
      cHost, ;
      nPort, ;
      cFrom, ;
      cTo, ;
      NIL /* CC */, ;
      {} /* BCC */, ;
      "test: body", ;
      "test: subject", ;
      NIL /* attachment */, ;
      cFrom, ;
      cPassword, ;
      "", ;
      NIL /* nPriority */, ;
      NIL /* lRead */, ;
      .T. /* lTrace */, ;
      .F., ;
      NIL /* lNoAuth */, ;
      NIL /* nTimeOut */, ;
      NIL /* cReplyTo */, ;
      nPort == 465 )

   RETURN
Eu uso aqui e não me deixa na mão inclusive com outlook, yahoo, gmail & Cia Ltda...


Saudações,
Itamar M. Lins Jr.

Email pelo Harbour

Enviado: 16 Jun 2015 21:12
por Itamar M. Lins Jr.
O pulo do gato!

Código: Selecionar todos

If hb_IsArray(aArqui)
Else
   aArqui := {aArqui}
EndIf

//Mudar essa linha 78 NIL /* attachment */ para:

      cBody , ;
      cSubJect , ;
      aArqui /* attachment */, ;
      cFrom, ;
      cPassword, ;

Basta colocar o caminho correto do XML e PDF na ARRAY!

Código: Selecionar todos

   aArqui := {"CAMINHO_DO_XML","CAMINHO_DO_PDF"}
Saudações,
Itamar M. Lins Jr.

Email pelo Harbour

Enviado: 17 Jun 2015 10:28
por rubens
Bom dia Itamar...

Então... mandei compilar com
hbmk2 Itamar -lhbssl -lhbtip

e deu um monte de erros na parte de SSL daí comentei as linhas SSL e compilou e executa mas não envia retorna um .F.
Erro envio de email.png
Codigo alterado

Código: Selecionar todos

/* Copyright 2009 Viktor Szakats (vszakats.net/harbour) */

#require "hbssl"
#require "hbtip"

/* #if ! defined( __HBSCRIPT__HBSHELL )
REQUEST __HBEXTERN__HBSSL__
#endif 
*/

#include "simpleio.ch"

PROCEDURE Main( cFrom, cPassword, cTo, cHost )

 LOCAL nPort
 LOCAL lSTARTTLS := .F.

/* IF ! tip_SSL()
   ? "Error: Requires SSL support"
   RETURN
ENDIF
*/
 
 hb_default( @cFrom  , "mdvinf@gmail.com" )
 hb_default( @cPassword, "*****" )
 hb_default( @cTo   , "mdvinf@hotmail.com" )
 hb_default( @cHost  , "smtp.gmail.com" )

 cHost := Lower( cHost )

 /* SMTPS works with SSL/TLS on port 465 and with STARTTLS
   on port 587. STARTTLS mode is fully automatic and require
   that SSL/TLS be disabled at first (it will be activated
   on request after STARTTLS command) */

 DO CASE
 CASE cHost == "apple" .OR. "@icloud.com" $ cFrom .OR. "@mac.com" $ cFrom .OR. "@me.com" $ cFrom
   cHost := "smtp.mail.me.com"; lSTARTTLS := .T.
 CASE cHost == "fastmail" .OR. "@fastmail.com" $ cFrom .OR. "@fastmail.fm" $ cFrom
   cHost := "mail.messagingengine.com"
 CASE cHost == "gmx.net" .OR. "@gmx.net" $ cFrom .OR. "@gmx.ch" $ cFrom .OR. "@gmx.de" $ cFrom
   cHost := "mail.gmx.net"; lSTARTTLS := .T.
 CASE cHost == "google" .OR. "@gmail.com" $ cFrom .OR. "@googlemail.com" $ cFrom
   cHost := "smtp.gmail.com"
 CASE cHost == "mail.ru" .OR. "@mail.ru" $ cFrom
   cHost := "smtp.mail.ru"
 CASE cHost == "netease" .OR. "@163.com" $ cFrom
   cHost := "smtp.163.com"
 CASE cHost == "office365"
   cHost := "smtp.office365.com"; lSTARTTLS := .T.
 CASE cHost == "outlook" .OR. "@outlook.com" $ cFrom .OR. "@hotmail.com" $ cFrom
   cHost := "smtp-mail.outlook.com"; lSTARTTLS := .T.
 CASE cHost == "sina" .OR. "@sina.com" $ cFrom
   cHost := "smtp.vip.sina.com"
 CASE cHost == "uol" .OR. "@uol.com.br" $ cFrom
   cHost := "smtps.uol.com.br"
 CASE cHost == "yahoo" .OR. "@yahoo.com" $ cFrom
   cHost := "smtp.mail.yahoo.com"
 CASE ":" $ cHost
   IF TUrl():New( cHost ):nPort != -1
    nPort := TUrl():New( cHost ):nPort
   ENDIF
   lSTARTTLS := ( nPort == 587 )
   cHost := TUrl():New( cHost ):cServer
 ENDCASE

 hb_default( @nPort, iif( lSTARTTLS, 587, 465 ) )

 ? "Host:", cHost, hb_ntos( nPort ), iif( lSTARTTLS, "(STARTTLS)", "" )

 ? hb_SendMail( ;
   cHost, ;
   nPort, ;
   cFrom, ;
   cTo, ;
   NIL /* CC */, ;
   {} /* BCC */, ;
   "test: body", ;
   "test: subject", ;
   NIL /* attachment */, ; // aArqui := {"CAMINHO_DO_XML","CAMINHO_DO_PDF"}
   cFrom, ;
   cPassword, ;
   "", ;
   NIL /* nPriority */, ;
   NIL /* lRead */, ;
   .T. /* lTrace */, ;
   .F., ;
   NIL /* lNoAuth */, ;
   NIL /* nTimeOut */, ;
   NIL /* cReplyTo */, ;
   nPort == 465 )

 RETURN
Erros quando nao comenta as linhas 06 e 18
Erros SSL.png
O que tá faltando ?

Rubens

Email pelo Harbour

Enviado: 17 Jun 2015 10:37
por Itamar M. Lins Jr.
O que tá faltando ?
Informar qual harbour vc está usando.
Eu uso o harbour 3.4 com Mingw
Estou vendo que usa o BCC danou-se, ai é que não sei mesmo. :-(

Saudações,
Itamar M. Lins Jr.

Email pelo Harbour

Enviado: 17 Jun 2015 11:44
por Itamar M. Lins Jr.
Me precipitei... agora entendi.
Neste caso está tudo ok.
Vc precisa passar os parâmetros só isso, para o Tip_MailSend().
Main( cFrom, cPassword, cTo, cHost )
Adicione o aArqui..., desmarque(mude) lá o attach... etc....

Saudações,
Itamar M. Lins Jr.

Email pelo Harbour

Enviado: 13 Ago 2015 18:37
por Softwhouse
Itamar,

Instalei o Harbour 3.4 com Mingw, tentei compilar o exemplo e deu um monte de erros. Podes colocar o script correto de compilação desse exemplo?

Grato!

Email pelo Harbour

Enviado: 13 Ago 2015 19:00
por Softwhouse
Conseguí compilar. Porém ao executar deu a seguinte mensagem:

O aplicativo ou a DLL C:\HB34\bin\Libeay32.dll não é uma imagem válida para o windows. Compare com o disco de instalação.

Estou usando Windows XP Pack3, algo a ver ?

Email pelo Harbour

Enviado: 15 Ago 2015 10:54
por Itamar M. Lins Jr.
Ola!
Use o Harbour já compilado 3.4
https://pctoledo.org/forum/viewto ... 43&t=16195

Saudações,
Itamar M. Lins Jr.

Email pelo Harbour

Enviado: 15 Ago 2015 16:09
por asimoes
Olá pessoal,

Esse assunto tá sendo bem discutido, estou tentando sem sucesso enviar email com uma conta do gmail.

Pegando exemplos do forum fiz este exemplo, e sempre dá falha.

Alguém pode ajudar? há alguma coisa errada neste código?
Tentei pela minha compilação do harbour-fork e também baixei o harbour compiado fork e nada.
Uso o mingw 5.01

Código: Selecionar todos

#include "hbgtinfo.ch"
#include "hbgtwvg.ch"
#include "wvgparts.ch"
#include "dbinfo.ch"
#include "fileio.ch"
#include "hbdyn.ch"
#include "simpleio.ch"

#require "hbtip"

PROCEDURE Main( cFrom, cPassword, cTo, cHost )

 LOCAL nPort

 hb_default( @cFrom , "<email@gmail.com>" )
 hb_default( @cPassword, "senha" )
 hb_default( @cTo , "destino@gmail.com" )
 hb_default( @cHost , "smtp.gmail.com" )

 cHost := Lower( cHost )

 cBody:="Corpo" 
 cSubJect:="Assunto"   
 aAnexo:= {hb_DirBase()+"gmail.prg"} 

 lRet := tip_MailSend( ;
      cHost, ;
      465 , ;
      cFrom, ;
      cTo, ;
      NIL /* CC */, ;
      {} /* BCC */, ;
      cBody , ;
      cSubJect , ;
      aAnexo /* attachment */, ;
      cFrom, ;
      cPassword, ;
      "", ;
      NIL /* nPriority */, ;
      NIL /* lRead */, ;
      .T. /* lTrace */, ;
      .F., ;
      NIL /* lNoAuth */, ;
      NIL /* nTimeOut */, ;
      NIL /* cReplyTo */, ;
      .T. )

/*
   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 addresses for CC (Carbon Copy)
   xBCC        -> Optional. Character string or array of email addresses 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.
   xTrace      -> Optional. If set to .T., a log file is created (smtp-<n>.log). Standard setting is .F.
                            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 10000 (10s)
   cReplyTo    -> Optional.
   lSSL        -> Optional. Need SSL at connect time (TLS need this param set to False)
   cSMTPPass   -> Optional.
   cCharset    -> Optional.
   cEncoding   -> Optional.
   cClientHost -> Optional. Domain name of the SMTP client in the format smtp.example.com OR client IP surrounded by brackets as in [200.100.100.5]
                            Note: This parameter is optional for backwards compatibility, but should be provided to comply with RFC 2812.
 */      
  
    If lRet
       hwg_Msginfo("email enviado")
    Else
       hwg_Msgexclamation("Falha enviando email")
    EndIf
 
RETURN


INIT FUNCTION AppSetup()
  
  ANNOUNCE hwg_ErrSys
  
  REQUEST HB_LANG_PT
  REQUEST HB_CODEPAGE_PT850
  HB_LANGSELECT("PT")
  HB_CDPSELECT( "PT850" ) 
  
  //GtSetupPalette()
    
  SETMODE(25,80)
 
  SetColor("W+/B")
  
  CLS
 
  SetColor("W+/B")
  
  IniciaJanela()
 

RETURN Nil 
 

FUNCTION IniciaJanela(nLi,nCi,nLf,nCf)
 
LOCAL oCrt
   HB_Default(@nLi,0)
   HB_Default(@nCi,0)
   HB_Default(@nLf,MaxRow())
   HB_Default(@nCf,MaxCol())
  
   
   cTituloJanela:="Teste envio de Email"
   
   HB_gtInfo(HB_GTI_FONTNAME, "Lucida Console")
   HB_gtInfo(HB_GTI_WINTITLE, cTituloJanela)
   HB_gtInfo(HB_GTI_ICONFILE, "" )
   HB_gtInfo(HB_GTI_CLOSABLE, .F. )
   HB_gtInfo(HB_GTI_ISGRAPHIC, .T. )
   HB_gtInfo(HB_GTI_STDERRCON, .T. )
   HB_gtInfo(HB_GTI_COMPATBUFFER, .T. ) 
   HB_gtInfo(HB_GTI_SPEC, HB_GTS_WNDSTATE, HB_GTS_WS_MAXIMIZED )
   HB_gtInfo(HB_GTI_SPEC, HB_GTS_SHOWWINDOW, SW_NORMAL )
   HB_GtInfo( HB_GTI_MAXIMIZED, .T. )
    
RETURN Nil
 
FUNCTION HB_GTSYS()
   REQUEST HB_GT_WVT_DEFAULT
   REQUEST HB_GT_WVT
   REQUEST HB_GT_WGU
   REQUEST HB_GT_WVG
RETURN Nil 

Email pelo Harbour

Enviado: 15 Ago 2015 20:19
por asimoes
Eu consegui gerar o executável e enviar o email usando openssl

A pergunta agora é a seguinte quais são as dlls necessárias para rodar junto com a aplicação.

Email pelo Harbour

Enviado: 15 Ago 2015 21:42
por asimoes
Pessoal,

Consegui gerar o executável e enviar o email usando Tip_MailSend
Fiz uma modificação que pode ser interessante para quem envia email e no campo De do gerenciador de email apareça somente o nome de quem está enviando e não o email ex.:

Para quem recebe o email ao invés de aparecer meuemail.@gmail.com vai aparecer somente Alexandre

Olhem o parâmetro cAlias

Outra coisa somente as dll : libeay32.dll tem que estar presente na pasta onde roda o executável.

Para gerar a lib hbssl usem este link: http://slproweb.com/products/Win32OpenSSL.html

Escolher o instalador: Win32OpenSSL-1_0_2d.exe

Para compilar o harbour incluir o set:

SET HB_WITH_OPENSSL=C:\OpenSSL-Win32\include

No seu script de compilação incluir:

hbssl.hbc
hbtip.hbc

Pronto deve funcionar, aqui eu consegui.

Código: Selecionar todos

/*
 * Copyright 2009 Viktor Szakats (vszakats.net/harbour)
 * www - http://harbour-project.org
 *
 * Gmail work with ssl on port 465 and with tls on port 587
 * tls mode is fully automatic and require that ssl must be disabled at first (We will activate it on request after STARTTLS command)
 */
#include "wvtwin.ch"
#include "hbcompat.ch"
#include "hbgtinfo.ch"
#include "hbgtwvg.ch"
#include "wvgparts.ch"
#include "dbinfo.ch"
#include "fileio.ch"
#include "hbdyn.ch"
#include "simpleio.ch"
#include "hbcurl.ch"

#require "hbssl"
#require "hbtip"

#if ! defined( __HBSCRIPT__HBSHELL )
   REQUEST __HBEXTERN__HBSSL__
#endif

PROCEDURE Main( cFrom, cPassword, cAlias, cTo, cHost )

 LOCAL nPort

 hb_default( @cFrom , "meuemail@gmail.com")
 hb_default( @cPassword, "123456789" )
 hb_default( @cTo , "paraemail@gmail.com" )
 hb_default( @cHost , "smtp.gmail.com" )
 hb_default( @cAlias , "Alexandre" )

 cHost := Lower( cHost )

 IF ! tip_SSL()
    hwg_MsgInfo("Error: Requires SSL support")
    RETURN
 ENDIF

 cBody:="Corpo do email" 
 cSubJect:="Assunto do email"   
 aAnexo:= {hb_DirBase()+"gmail.prg"} 
 nPriority:=NIL
 cAlias := cAlias +"<"+cFrom+">"
 
 lRet := tip_MailSend( ;
      cHost, ;
      465 , ;
      cAlias, ;
      cTo, ;
      NIL, ;
      {} , ;
      cBody , ;
      cSubJect , ;
      aAnexo , ;
      cFrom, ;
      cPassword, ;
      "", ;
      nPriority , ;
      NIL , ;
      .F. , ;
      .F., ;
       NIL , ;
      NIL , ;
      NIL , ;
      .T. )
  
/*
   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 addresses for CC (Carbon Copy)
   xBCC        -> Optional. Character string or array of email addresses 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.
   xTrace      -> Optional. If set to .T., a log file is created (smtp-<n>.log). Standard setting is .F.
                            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 10000 (10s)
   cReplyTo    -> Optional.
   lSSL        -> Optional. Need SSL at connect time (TLS need this param set to False)
   cSMTPPass   -> Optional.
   cCharset    -> Optional.
   cEncoding   -> Optional.
   cClientHost -> Optional. Domain name of the SMTP client in the format smtp.example.com OR client IP surrounded by brackets as in [200.100.100.5]
                            Note: This parameter is optional for backwards compatibility, but should be provided to comply with RFC 2812.
 */      
   
    If lRet
       hwg_Msginfo("email enviado")
    Else
       hwg_Msgexclamation("Falha enviando email")
    EndIf
 
RETURN


INIT FUNCTION AppSetup()
  
  ANNOUNCE hwg_ErrSys
  
  REQUEST HB_LANG_PT
  REQUEST HB_CODEPAGE_PT850
  HB_LANGSELECT("PT")
  HB_CDPSELECT( "PT850" ) 
  
  //GtSetupPalette()
    
  SETMODE(25,80)
 
  SetColor("W+/B")
  
  CLS
 
  SetColor("W+/B")
  
  IniciaJanela()
 

RETURN Nil 
 

FUNCTION IniciaJanela(nLi,nCi,nLf,nCf)
 
LOCAL oCrt
   HB_Default(@nLi,0)
   HB_Default(@nCi,0)
   HB_Default(@nLf,MaxRow())
   HB_Default(@nCf,MaxCol())
  
   
   cTituloJanela:="Teste envio de Email"
   
   HB_gtInfo(HB_GTI_FONTNAME, "Lucida Console")
   HB_gtInfo(HB_GTI_WINTITLE, cTituloJanela)
   HB_gtInfo(HB_GTI_ICONFILE, "" )
   HB_gtInfo(HB_GTI_CLOSABLE, .F. )
   HB_gtInfo(HB_GTI_ISGRAPHIC, .T. )
   HB_gtInfo(HB_GTI_STDERRCON, .T. )
   HB_gtInfo(HB_GTI_COMPATBUFFER, .T. ) 
   HB_gtInfo(HB_GTI_SPEC, HB_GTS_WNDSTATE, HB_GTS_WS_MAXIMIZED )
   HB_gtInfo(HB_GTI_SPEC, HB_GTS_SHOWWINDOW, SW_NORMAL )
   HB_GtInfo( HB_GTI_MAXIMIZED, .T. )
    
RETURN Nil
 
FUNCTION HB_GTSYS()
   REQUEST HB_GT_WVT_DEFAULT
   REQUEST HB_GT_WVT
   REQUEST HB_GT_WGU
   REQUEST HB_GT_WVG
RETURN Nil