Categories
Common

QlikView Send Email by Passing Report ID as Parameter

SUB sendOneMail(reportFile)

Dim objEmail
Dim strMailTo

Const cdoSendUsingPort = 2 ' Send the message using SMTP
Const cdoBasic = 1 	   'basic (clear-text) authentication
'Const cdoNTLM = 2 	   'NTLM

SMTPServer = "smtp.gmail.com" 
SMTPPort = 465             ' Port number for SMTP
Const SMTPTimeout = 60     ' Timeout for SMTP in seconds

mailusername = "youruser@gmail.com"
mailpassword = "topsecret"

'Get Selected values from field "mailto"
Set objSelected = ActiveDocument.Fields("MailAdresse").GetPossibleValues

'Send mail
Set objEmail = CreateObject("CDO.Message")
Set objConf = objEmail.Configuration
Set objFlds = objConf.Fields

'-------------------------------------------------------------------
' SMTP server details	

With objFlds
		.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/smtpserverport") = SMTPPort
	  	.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
	    	.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = SMTPTimeout
	    	.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
	    	.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailusername
		.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailpassword
	    	.Update
End With

objEmail.To = "philipp.frenzel@myplace.eu" ' remove the last ; in list
objEmail.To = strMailTo
objEmail.From = "reporting@myplace.eu"
objEmail.Subject = getVariable("varMailSubject")
objEmail.TextBody = getText("MsgBody")
objEmail.AddAttachment reportFile
objEmail.Send

Set objFlds = Nothing
Set objConf = Nothing
Set objEmail = Nothing

END SUB

Leave a Reply