*------------------------------------------------------------------
* Consulta cadastro clientes e filtra registros bloqueados
*------------------------------------------------------------------
#include "Ap5Mail.ch"
User function fmailcli()
dbselectarea("SA1")
cExpressao := "SA1->A1_MSBLQL<>'1' .and. !empty(SA1->A1_EMAIL"
bExpressao := {|| SA1->A1_MSBLQL<>'1' .and. !empty(SA1->A1_EMAIL) }
DbSetFilter(bExpressao ,cExpressao)
dbgotop()
While !Eof()
fSend(SA1->A1_EMAIL)
dbskip()
Enddo
Return
Static function fSend(_cTo)
Local cSubject, cBCC, cCC := ''
lHtml := .f.
cFrom := 'Exemplo Email <faturamento@empresa.com.br>'
cSubject := 'Lista de Produtos'
_cHTML := MemoRead("\workflow\mailings\mCalend.html")
U_SduMandaEmail(_cTo,cCC,cBCC,cSubject,cFrom,_cHTML,lHtml)
Return
*----------------------------------------------------------------------------------------------
User Function SduMandaEmail(cPara,cCopia,cConhCopia,cAssunto,cDe,cTexto,lHtml,cFile)
Local lHtml := Iif(ValType(lHtml)="U",.f.,lHtml)
Local lOk := .F.
Local cAccount := GetMv("MV_RELACNT")
Local cPassword := GetMv("MV_RELPSW")
Local cServer := GetMv("MV_RELSERV")
Local cDe := Iif(cDe==Nil,'Servidor Protheus <workflow@empresa.com.br>',cDe)
Connect Smtp Server cServer Account cAccount Password cPassword Result lOk
If lOk
If ! MailAuth(cAccount,cPassword)
Get Mail Error cErrorMsg
Help("",1,"AVG0001056",,"Error: "+cErrorMsg,2,0)
Disconnect Smtp Server Result lOk
if !lOk
Get Mail Error cErrorMsg
Help("",1,"AVG0001056",,"Error: "+cErrorMsg,2,0)
endif
Return ( .f. )
EndIf
If !Empty(cCopia)
if lHtml
If !Empty(cFile)
Send Mail From cDe To cPara CC cCopia Subject cAssunto Body cTexto Attachment cFile Result lOk
Else
Send Mail From cDe To cPara CC cCopia Subject cAssunto Body cTexto Result lOk
EndIf
else
If !Empty(cFile)
Send Mail From cDe To cPara CC cCopia Subject cAssunto Body cTexto Format Text Attachment cFile Result lOk
Else
Send Mail From cDe To cPara CC cCopia Subject cAssunto Body cTexto Format Text Result lOk
EndIf
endif
Else
if lHtml
If !Empty(cFile)
Send Mail From cDe To cPara BCC cConhCopia Subject cAssunto Body cTexto Attachment cFile Result lOk
Else
Send Mail From cDe To cPara BCC cConhCopia Subject cAssunto Body cTexto Result lOk
EndIf
else
If !Empty(cFile)
Send Mail From cDe To cPara BCC cConhCopia Subject cAssunto Body cTexto Format Text Attachment cFile Result lOk
Else
Send Mail From cDe To cPara BCC cConhCopia Subject cAssunto Body cTexto Format Text Result lOk
EndIf
endif
EndIf
If ! lOk
Get Mail Error cErrorMsg
Help("",1,"AVG0001056",,"Error: "+cErrorMsg,2,0)
EndIf
Else
Get Mail Error cErrorMsg
Help("",1,"AVG0001057",,"Error: "+cErrorMsg,2,0)
EndIf
Disconnect Smtp Server
Return
Nenhum comentário :
Postar um comentário