Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
poojask123
Partner - Creator
Partner - Creator

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
m_woolf
Master II
Master II

on error resume next

objMsg.Send

msgbox err.number & "  " & err.description

View solution in original post

4 Replies
m_woolf
Master II
Master II

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

poojask123
Partner - Creator
Partner - Creator
Author

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

m_woolf
Master II
Master II

on error resume next

objMsg.Send

msgbox err.number & "  " & err.description

poojask123
Partner - Creator
Partner - Creator
Author

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.