Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

poojask123
New Contributor III

Email Macro not working

Hi,

I have a requirement to send a report as email attachment to a user, i found the below code on the community and used the same, but the execution stops at ObjMsg.Send

Sending Emails using Macro - is the post i referred along with many others.

I am unable to find a reason why it doesnt execute. I am passing the service account user credentials. Can anyone please let me know if there are any other security reasons why my codes doesn't send the email?

**********************************************************************

Sub SendReport

ActiveDocument.Sheets("SH01").Activate 'edit the sheet

'ActiveDocument.reload

set objExcel=ActiveDocument.GetSheetObject("TB01") 'edit the sheet object

strDate = Year(Date()) &"-"& month(date()) &"-"& Day(Date())

filepath="E:\Qlikview Documents\Report_"&strDate&".xls"   'edit the location of file

objExcel.ExportBiff filepath

ActiveDocument.GetApplication.Sleep 5000

SendGMail

ActiveDocument.Save

set objExcel=nothing

set strDate=nothing

set filepath=nothing

End Sub

Sub SendGMail()

MsgBox "Report Exported Successfully"

strDate = Year(Date()) &"-"& month(date()) &"-"& Day(Date())

filepath="E:\Qlikview Documents\Report_"&strDate&".xls"

Set objMsg = CreateObject("CDO.Message")

Set msgConf = CreateObject("CDO.Configuration")

'Server Configuration

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

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

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

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

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "c***\*****n" 'type your mail id

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "********" 'Type your account Password

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

msgConf.Fields.Update

Msgbox("test123")

'End With

objMsg.To = "tomail@domain.com" ' type to mail id

objMsg.From = "frommail@domain.com" 'type from mail id

objMsg.Subject = "Test mail"

objMsg.HTMLBody = "QlikView Test Mail"

'objMsg.AddAttachment "D:\Image.jpg"

objMsg.AddAttachment   filepath    ' Attachement object

objMsg.Sender = "Mr. Name"

Msgbox("test4563")

Set objMsg.Configuration = msgConf

Msgbox("send")

' Send

objMsg.Send

Msgbox("test")

Msgbox("Email Sent Successfully")

' Clear

Set objMsg = nothing

Set msgConf = nothing

End Sub

************************************************************************************************************************

1 Solution

Accepted Solutions
mwoolf
Honored Contributor II

Re: Email Macro not working

on error resume next

objMsg.Send

msgbox err.number & "  " & err.description

View solution in original post

4 Replies
mwoolf
Honored Contributor II

Re: Email Macro not working

You might turn on error handling to see what error is being returned by the .Send line.

poojask123
New Contributor III

Re: Email Macro not working

Is it something that i have to write as part of the code ? I am not very aware of it. Please help.

mwoolf
Honored Contributor II

Re: Email Macro not working

on error resume next

objMsg.Send

msgbox err.number & "  " & err.description

View solution in original post

poojask123
New Contributor III

Re: Email Macro not working

Thank you. The error was with respect to the transport layer and i disabled SSL in the code and it worked fine. Since the mail is been sent within the network, i hope disabling SSL should'nt be a problem.