Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Enviar Email

Eu procurei aqui na comunidade, mas achei um script para ser executado via Macro. Mas aqui nao funcionou. Alguem ja enviou email pelo qlikview??? E se sim, alguem ja conseguiu fazer isso após executar o script???

Para enviar email achei o seguinte código

function mailrapport(teste)

    Dim objEmail

    Const cdoSendUsingPort = 2     ' Send the message using SMTP

    Const cdoAnonymous = 0     'Do not authenticate

    Const cdoBasic = 1         'basic (clear-text) authentication

    Const cdoNTLM = 2         'NTLM

    SMTPServer =  "Seuemail@gmail.com"

    Const SMTPPort = 25                 ' Port number for SMTP

    Const SMTPTimeout = 60              ' Timeout for SMTP in seconds

    'Sending mail

    Set objEmail = CreateObject("CDO.Message")

    Set objConf = objEmail.Configuration

    Set objFlds = objConf.Fields

    With objFlds

        '---------------------------------------------------------------------

           ' SMTP server details

           .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort

           .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer

           .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous

        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort

        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

          .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = SMTPTimeout

           .Update

        '---------------------------------------------------------------------

    End With

    objEmail.To = "Seuemail@gmail.com"      'Email Recipient

    objEmail.From = "Seuemail@gmail.com"                        'Email Sender

    objEmail.Subject = "The name of the report"                        ' Subject

    objEmail.TextBody = "some text in the body of the mail"        'Text Body         

    objEmail.AddAttachment = Nothing       ' Attachement

    objEmail.Send

    Set objFlds = Nothing

    Set objConf = Nothing

    Set objEmail = Nothing

end function

1 Solution

Accepted Solutions
fosuzuki
Partner - Specialist III
Partner - Specialist III

O que eu já fiz foi o seguinte:

1. no script, checo algumas condições e vou populando uma tabela com os parametros (Endereço, Assunto, Corpo do email) dos emails que quero enviar.

Controle_Envio_Email:

load  '$(sDestinatarios)' as sEmailTo,

            '$(sDestinatariosBcc)' as sEmailBcc,

            'QlikView - Alerta' as sEmailSubject,

            '$(sEmailTextBody)' as sEmailTextBody

autogenerate(1);

2. depois, no final do script, faço um loop nessa tabela e para cada registro eu chamo a macro para enviar os emails

if( NoOfRows('Controle_Envio_Email') > 0 ) then

     let nEmails = NoOfRows('Controle_Envio_Email');

     for y = 0 to nEmails - 1

          let sEmailTo = peek('sEmailTo', y, 'Controle_Envio_Email');

          let sEmailBcc = peek('sEmailBcc', y, 'Controle_Envio_Email');

          let sEmailSubject = peek('sEmailSubject', y, 'Controle_Envio_Email');

          let sEmailTextBody = peek('sEmailTextBody', y, 'Controle_Envio_Email');

 

          // envia os os e-mails para os centros de custos.

          let x = sendEmail('$(sEmailTo)', '$(sEmailBcc)', '$(sEmailSubject)', '$(sEmailTextBody)', '$(sSMTPServerIP)', '$(sSMTPServerPort)');

     next

end if

3. E a macro é:

function sendEmail(sEmailTo, sEmailBcc, sEmailSubject, sEmailTextBody, sSMTPServerIP, sSMTPServerPort)

          ' Object creation

          Set objMsg = CreateObject("CDO.Message")

          Set msgConf = CreateObject("CDO.Configuration")

 

          '==This section provides the configuration information for the remote SMTP server.

          ' Server Configuration

          msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

          'Name or IP of Remote SMTP Server

          msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSMTPServerIP

          'Server port (typically 25)

          msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = sSMTPServerPort

 

          msgConf.Fields.Update

 

          ' Email

'          objMsg.Sender = "QlikView Service"

          objMsg.Sender = ""

          objMsg.From = "srv.qlikview@xxxxx.com.br"

          objMsg.To = sEmailTo

          if len(sEmailBcc) > 0 then

                    objMsg.Bcc = "srv.qlikview@xxxxx.com.br, " & sEmailBcc

          else

                    objMsg.Bcc = "srv.qlikview@xxxxx.com.br"

          end if

          objMsg.Subject = sEmailSubject

          objMsg.TextBody = sEmailTextBody

 

          Set objMsg.Configuration = msgConf

 

          ' Send

          objMsg.Send

 

          ' Clear

          Set objMsg = nothing

          Set msgConf = nothing

end function

Obs: no começo do script eu defino o IP do servidor e porta:

set sSMTPServerIP = '123.456.789.0';

set sSMTPServerPort = 25;

Obs2: É importante que na tela de Edição do Script, no painel inferior, aba Configurações, você marque a opção de permissão de execução de programas externos.

Espero que isso te ajude.

Abs

Fernando

View solution in original post

21 Replies
Not applicable
Author

Boa tarde!

Você não poderia simplesmente utilizar um disparador? É bem mais simples.

Att.

Rebeca Gums

Not applicable
Author

Qual disparador?...

Eu estou pesquisando aqui, e todas as pesquisas de email, as pessoas utilizam Macro. Ai eu usei um disparador para executar a macro após recarregar. Mas antes de fazer isso eu estou tentando fazer essa macro funcionar, mas até agora nada... ahahahahahahahah.

Not applicable
Author

Perae...tenho um exemplo. Vou procurar e te envio.

Achei aqui, mas é o envio de email ligado a um Alerta. Me confundi. De repente serve para você. Segue em anexo.

Att.

Rebeca

Not applicable
Author

Como vc configurou o qlikview para enviar email para você?

O que eu preciso fazer é que o qlikview mande um email se as horas trabalhadas estiverem em 80% do projeto eu envio email para o gerente de projeto.Preciso fazer isso, o email eu vou pegar de um campo.

Not applicable
Author

Na aplicação que eu te enviei, olha em Ferramentas->Alertas!

Eu fiz os testes configurando nas preferências dos usuário para poder enviar o email.

Att.

Rebeca

fosuzuki
Partner - Specialist III
Partner - Specialist III

O que eu já fiz foi o seguinte:

1. no script, checo algumas condições e vou populando uma tabela com os parametros (Endereço, Assunto, Corpo do email) dos emails que quero enviar.

Controle_Envio_Email:

load  '$(sDestinatarios)' as sEmailTo,

            '$(sDestinatariosBcc)' as sEmailBcc,

            'QlikView - Alerta' as sEmailSubject,

            '$(sEmailTextBody)' as sEmailTextBody

autogenerate(1);

2. depois, no final do script, faço um loop nessa tabela e para cada registro eu chamo a macro para enviar os emails

if( NoOfRows('Controle_Envio_Email') > 0 ) then

     let nEmails = NoOfRows('Controle_Envio_Email');

     for y = 0 to nEmails - 1

          let sEmailTo = peek('sEmailTo', y, 'Controle_Envio_Email');

          let sEmailBcc = peek('sEmailBcc', y, 'Controle_Envio_Email');

          let sEmailSubject = peek('sEmailSubject', y, 'Controle_Envio_Email');

          let sEmailTextBody = peek('sEmailTextBody', y, 'Controle_Envio_Email');

 

          // envia os os e-mails para os centros de custos.

          let x = sendEmail('$(sEmailTo)', '$(sEmailBcc)', '$(sEmailSubject)', '$(sEmailTextBody)', '$(sSMTPServerIP)', '$(sSMTPServerPort)');

     next

end if

3. E a macro é:

function sendEmail(sEmailTo, sEmailBcc, sEmailSubject, sEmailTextBody, sSMTPServerIP, sSMTPServerPort)

          ' Object creation

          Set objMsg = CreateObject("CDO.Message")

          Set msgConf = CreateObject("CDO.Configuration")

 

          '==This section provides the configuration information for the remote SMTP server.

          ' Server Configuration

          msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

          'Name or IP of Remote SMTP Server

          msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSMTPServerIP

          'Server port (typically 25)

          msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = sSMTPServerPort

 

          msgConf.Fields.Update

 

          ' Email

'          objMsg.Sender = "QlikView Service"

          objMsg.Sender = ""

          objMsg.From = "srv.qlikview@xxxxx.com.br"

          objMsg.To = sEmailTo

          if len(sEmailBcc) > 0 then

                    objMsg.Bcc = "srv.qlikview@xxxxx.com.br, " & sEmailBcc

          else

                    objMsg.Bcc = "srv.qlikview@xxxxx.com.br"

          end if

          objMsg.Subject = sEmailSubject

          objMsg.TextBody = sEmailTextBody

 

          Set objMsg.Configuration = msgConf

 

          ' Send

          objMsg.Send

 

          ' Clear

          Set objMsg = nothing

          Set msgConf = nothing

end function

Obs: no começo do script eu defino o IP do servidor e porta:

set sSMTPServerIP = '123.456.789.0';

set sSMTPServerPort = 25;

Obs2: É importante que na tela de Edição do Script, no painel inferior, aba Configurações, você marque a opção de permissão de execução de programas externos.

Espero que isso te ajude.

Abs

Fernando

Not applicable
Author

Eu utilizei já macro para disparar email.

Ainda a macro gerava o relatorio Qlikview em PDF e deixava como anexo do email.

Vou procurar aqui o script e posto mais tarde.

Abraços

Not applicable
Author

Eu entendi como funciona, mas nao to conseguindo confiugrar para enviar o email, ele gera um erro pra mim. Mesmo depois de eu ter configurado em Preferencias de usuários, ai eu fiz o teste em preferencia de usuário, ele ta dando erro.

Not applicable
Author

Obrigado Fernando, eu adaptei seu código aqui,e está rodando que é uma beleza....