Enviando e-mail com a função GPEMail
A função GPEMail é uma função utilizada no módulo do RH, eu a achei bem interessante como sendo uma função já pronta e de fácil uso.
No exemplo abaixo irei mostrar seu uso, mas antes de usá-la é preciso que você tenha alguns parametros preenchidos:
MV_EMCONTA
MV_RELSERV
MV_EMSENHA
Estes parametros devem estar declarados como Private.
Sintaxe:
gpeMail(cAssunto,cMensagem,cPara,aArquivos)
Para enviar no formato HTML, inclua tags html
Exemplo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#Include 'Protheus.ch' //U_testemail() User Function testemail() Local cMensagem := "" Local cArquivo := "\system\seuarquivo.ext" Local aArquivos := {} Local cPara := "email destinatario" Private cMailConta := NIL Private cMailServer := NIL Private cMailSenha := NIL cMailConta :=If(cMailConta == NIL,GETMV("MV_EMCONTA"),cMailConta) //Conta utilizada p/envio do email cMailServer :=If(cMailServer == NIL,GETMV("MV_RELSERV"),cMailServer) //Server cMailSenha :=If(cMailSenha == NIL,GETMV("MV_EMSENHA"),cMailSenha) If Empty(cEmail) Return Endif //Verifica se existe o SMTP Server If Empty(cMailServer) Help(" ",1,"SEMSMTP")//"O Servidor de SMTP nao foi configurado !!!" ,"Atencao" Return(.F.) EndIf //Verifica se existe a CONTA If Empty(cMailServer) Help(" ",1,"SEMCONTA")//"A Conta do email nao foi configurado !!!" ,"Atencao" Return(.F.) EndIf aadd(aArquivos,cArquivo) cMensagem += '<html>' cMensagem += '<body>' cMensagem += '<font face="arial" size="2"><p>Prezado,<br>' cMensagem += 'Segue em anexo seu Holerith referente a competencia XX/XXXX<br><br>' cMensagem += 'Atenciosamente,<br>' cMensagem += 'XXXXXXXXX</font>' cMensagem += '</body></html>' GPEMail(cAssunto,cMensagem,cPara,aArquivos) Return |