× Linguagem de Programação ADVPL

Perguntas Erro 54 na conexão SMTP no envio de email.

Mais
9 anos 3 meses atrás #27004 por renatosever
Boa tarde, Estou tentando disparar email pela rotina abaixo, mas da erro 54 na conexao smtp.
O email que estou tentando configurar é gmail. será que alguem pode ajudar?

Segue código abaixo:



User Function EnvMail(_cSubject, _cBody, _cMailTo, _cCC, _cAnexo, _cConta, _cSenha)

Local _cMailS := GetMv("MV_XMLSMTP") //BUSCA CONFIGURAÇÃO SMTP EMAIL DE DISPARO XML
Local _cAccount := GetMV("MV_XMLMAIL") //BUSCA CONFIGURAÇÃO DE EMAIL DE DISPARO XML
Local _cPass := GetMV("MV_XMLPASS") //BUSCA CONFIGURAÇÃO SENHA DE EMAIL DE DISPARO XML
Local _nPort := Val(GetMV("MV_XMLPORT")) //BUSCA CONFIGURAÇÃO DA PORTA DE EMAIL DE DISPARO XML
Local lAuth := GetMv("MV_XMLAUTH",,.F.) //BUSCA CONFIGURAÇÃO DE EMAIL DE DISPARO XML SE USA AUTENTICAÇÃO .T. ou .F.

Local oServer := nil
Local oMessage := nil
Local nRet := 0
Local nTimeOut := 20
Local cUser := _cAccount
// Local lAuth := .T.
Local cCorpoM := ""
Local cAssunto := ""
// Local aFiles := Directory(_cAnexo)

//Local aFiles := Directory(cPath + Alltrim("*.*"))
Local nCount := 0

cAssunto := AllTrim(_cSubject)
oServer := TMailManager():New()
// Usa SSL na conexao
oServer:setUseSSL(.F.)//GetMv("MV_RELAUTH",,.F.))

oServer:Init( "", _cMailS, _cAccount, _cPass, 0, _nPort)

if (nTimeout <= 0)
conout("[TIMEOUT] DISABLE")
else
conout("[TIMEOUT] ENABLE()")
nRet := oServer:SetSmtpTimeOut( 120 )

If nRet != 0
conout("[TIMEOUT] Fail to set")
conout("[TIMEOUT][ERROR] " + str(nRet,6) , oServer:GetErrorString(nRet))

Return .F.
EndIf
Endif

Conout("Configuração da Conta Email")
Conout("Servidor de Email: " + _cMailS)
Conout("Conta de Email: " + _cAccount)
Conout("Senha Email: " + _cPass)
Conout("Porta comunicação: " + cValToChar(_nPort))
Conout("Autenticação? .T.(sim) .F.(nao): " + cValToChar(lAuth))

Conout( "[SMTPCONNECT] connecting ..." )
nRet := oServer:SmtpConnect()

If nRet != 0
conout("[SMTPCONNECT] Falha ao conectar" )
conout("[SMTPCONNECT][ERROR] " + str(nRet,6) , oServer:GetErrorString(nRet))
Return .F.
Else
conout( "[SMTPCONNECT] Sucesso ao conectar" )
EndIf

If lAuth
conout("[AUTH] ENABLE")
conout("[AUTH] TRY with ACCOUNT() and PASS()")
// try with account and pass
nRet := oServer:SMTPAuth(_cAccount, _cPass)
If nRet != 0
conout("[AUTH] FAIL TRY with ACCOUNT() and PASS()")
conout("[AUTH][ERROR] " + str(nRet,6) , oServer:GetErrorString(nRet))
conout("[AUTH] TRY with USER() and PASS()")
// try with user and pass
nRet := oServer:SMTPAuth(cUser, _cPass)
If nRet != 0
conout("[AUTH] FAIL TRY with USER() and PASS()")
conout("[AUTH][ERROR] " + str(nRet,6), oServer:GetErrorString(nRet))
Return .F.
else
conout("[AUTH] SUCEEDED TRY with USER() and PASS()")
Endif
else
conout("[AUTH] SUCEEDED TRY with ACCOUNT and PASS")
Endif
Else
conout("[AUTH] DISABLE")
Endif

conout("[MESSAGE] Criando mail message")
oMessage := TMailMessage():New()
oMessage:Clear()
oMessage:cFrom := _cAccount
oMessage:cTo := _cMailTo
oMessage:cCc := ""
oMessage:cBcc := ""
oMessage:cSubject := cAssunto+ " " + dtoc(date()) + " " + time()
cCorpoM := ''

cCorpoM += "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' ' www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd '> "
cCorpoM += "<html xmlns=' www.w3.org/1999/xhtml '> "
cCorpoM += "<head> "
cCorpoM += "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /> "
cCorpoM += "<style type='text/css'> "
cCorpoM += "<!-- "
cCorpoM += "body,td,th { "
cCorpoM += " font-family: Arial, Helvetica, sans-serif; "
cCorpoM += " font-size: 12pt; "
cCorpoM += "} "
cCorpoM += "--> "
cCorpoM += "</style></head> "
cCorpoM += "<body> "
cCorpoM += "<br>"
cCorpoM += AllTrim(_cBody)
cCorpoM += "<br>"
cCorpoM += "<br>"
cCorpoM += "<br>"
cCorpoM += "<br>"
cCorpoM += "Este email é disparado automaticamente após a importação do XML - Favor não Responder."
cCorpoM += "<br>"
cCorpoM += "________________________________________________________________________"
cCorpoM += "<br>"
cCorpoM += "Desenvolvido por departamento TI."
cCorpoM += "</body> "
cCorpoM += "</html>"
//oMessage:MsgBodyType( "text/html" )
oMessage:cBody := cCorpoM

conout("[SEND] Sending ...")
nRet := oMessage:Send( oServer )

If nRet != 0
conout("[SEND] Fail to send message" )
conout("[SEND][ERROR] " + str(nRet,6) , oServer:GetErrorString(nRet))
else
conout( "[SEND] Success to send message" )
EndIf

conout("[DISCONNECT] smtp disconnecting ... ")
nRet := oServer:SmtpDisconnect()

If nRet != 0
conout("[DISCONNECT] Fail smtp disconnecting ... ")
conout("[DISCONNECT][ERROR] " + str(nRet,6) , oServer:GetErrorString(nRet))
else
conout("[DISCONNECT] Success smtp disconnecting ... ")
EndIf

MsgInfo("Email enviado com sucesso para: " + AllTrim(_cMailTo), " -")


Return

Por favor Acessar ou Registrar para participar da conversa.

Mais
9 anos 3 meses atrás #27021 por Jafreal
Boa tarde

Tive esse mesmo problema. Faça o seguinte veja o teu servidor de aplicação, pois o erro é lá ele não deixa vc "sair". Eu revi as configurações da rede do firewall.

Por favor Acessar ou Registrar para participar da conversa.

Mais
9 anos 3 meses atrás #27030 por renatosever
Obrigado Aguiar, mas não é isto, desativei o firewall e coloquei o mesmo email que usa pra transmitir NFe.
Mesmo assim não deu.

Grato

Por favor Acessar ou Registrar para participar da conversa.

Tempo para a criação da página:0.109 segundos
Joomla templates by a4joomla