Email pelo Harbour
Enviado: 01 Abr 2015 20:25
Na sua função a porta eh 465 para gmail?
Janio
Janio
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
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, ;
Código: Selecionar todos
aArqui := {"CAMINHO_DO_XML","CAMINHO_DO_PDF"}
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
Informar qual harbour vc está usando.O que tá faltando ?
Adicione o aArqui..., desmarque(mude) lá o attach... etc....Main( cFrom, cPassword, cTo, cHost )
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
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