'========================= functions for printing PDF and sending mail ============================
sub sendReport
tempFolder = "C:\"
Set oReports = ActiveDocument.Fields("reportID").GetPossibleValues
Dim arrReports()
if oReports.Count > 0 then
redim arrReports(oReports.Count)
for i = 0 to oReports.Count -1
reportID = oReports.Item(i).Text
set rep = ActiveDocument.GetReport(reportID)
reportName = rep.Name
reportFile = tempFolder & reportID & "_" & reportName & ".pdf"
deleteReport (reportFile) 'Cleaning out any previous report
arrReports(i) = reportFile
' Print report to PDF
printReportPDF reportID, reportFile
' Check the file is printed, before trying to send it
checkOutputFile(reportFile)
next
' Send report
sendMail arrReports
else
msgbox ("You must select at least one report")
end if
' Delete the temporary reports
for each item in arrReports
deleteReport(item)
next
' Don't forget to activate Save As again after print!
call activateSaveAs()
set fileTest = nothing
end sub
function deleteReport(rFile)
set oFile = createObject("Scripting.FileSystemObject")
currentStatus = oFile.FileExists(rFile)
if currentStatus = true then
oFile.DeleteFile(rFile)
end if
set oFile = Nothing
end function
function sendMail(reportFiles)
Dim objEmail
Dim strMailTo
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
Const SMTPServer = "smtp.accovia.com"
Const SMTPPort = 25 ' Port number for SMTP
Const SMTPTimeout = 60 ' Timeout for SMTP in seconds
'Get Selected values from field "mailto"
Set objSelected = ActiveDocument.Fields("mailto").GetSelectedValues
if objSelected.Count = 0 then ' Nothing Selected
msgbox ("No e-mail recipient selected")
exit function
else
'Send mail
Set objEmail = CreateObject("CDO.Message")
Set objConf = objEmail.Configuration
Set objFlds = objConf.Fields
With objFlds
'---------------------------------------------------------------------
' SMTP server details
.Item("schemas.microsoft.com/.../sendusing") = cdoSendUsingPort
.Item("schemas.microsoft.com/.../smtpserver") = SMTPServer
.Item("schemas.microsoft.com/.../smtpauthenticate") = cdoAnonymous
.Item("schemas.microsoft.com/.../smtpserverport") = SMTPPort
.Item("schemas.microsoft.com/.../smtpusessl") = False
.Item("schemas.microsoft.com/.../smtpconnectiontimeout") = SMTPTimeout
.Update
'---------------------------------------------------------------------
End With
For i = 0 to objSelected.Count-1 ' create mailTo list
strMailTo = strMailTo & objSelected.item(i).Text & ";"
next
strMailTo = left(strMailTo,len(strMailTo)-1) ' remove the last ; in list
objEmail.To = strMailTo
objEmail.From = "Travel-Intelligence@accovia.com"
objEmail.Subject = getVariable("mailSubject")
objEmail.TextBody = getText("BodyTX")
for each item in reportFiles ' Add selected reports to mail
if item <>"" then
objEmail.AddAttachment item
end if
next
objEmail.Send
Set objFlds = Nothing
Set objConf = Nothing
Set objEmail = Nothing
end if
msgbox ("Mail Sent")
end function
function sendMailTest()
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
Const SMTPServer = "smtp.accovia.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("schemas.microsoft.com/.../sendusing") = cdoSendUsingPort
.Item("schemas.microsoft.com/.../smtpserver") = SMTPServer
.Item("schemas.microsoft.com/.../smtpauthenticate") = cdoAnonymous
.Item("schemas.microsoft.com/.../smtpserverport") = SMTPPort
.Item("schemas.microsoft.com/.../smtpusessl") = False
.Item("schemas.microsoft.com/.../smtpconnectiontimeout") = SMTPTimeout
.Update
'---------------------------------------------------------------------
End With
objEmail.To = "philippe_motillon@videotron.ca"
objEmail.From = "philippe@accovia.com"
objEmail.Subject = "test"
objEmail.TextBody = "message de test"
objEmail.Send
Set objFlds = Nothing
Set objConf = Nothing
Set objEmail = Nothing
msgbox ("Test Mail Sent")
end function
function printReportPDF(oReport, pdfOutputFile)
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\OutputFile", pdfOutputFile, "REG_SZ"
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\BypassSaveAs", "1", "REG_SZ"
'QV Print
ActiveDocument.PrintReport oReport, "QlikViewPDF", false
set WSHShell = nothing
end function
function activateSaveAs()
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\OutputFile", "", "REG_SZ"
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\BypassSaveAs", "0", "REG_SZ"
set WSHShell = nothing
end function
function checkOutputFile(pdfFile)
Set fileTest = CreateObject("Scripting.FileSystemObject")
currentStatus = fileTest.FileExists (pdfFile)
if currentStatus = false then
rem ** let QV sleep for 1 seconds **
ActiveDocument.GetApplication.Sleep 1000
checkOutputFile(pdfFile)
end if
set fileTest = nothing
end function
'==================== functions to get the reports in the document ==============
function countReports
set ri = ActiveDocument.GetDocReportInfo
countReports = ri.Count
end function
function getReportInfo (i)
set ri = ActiveDocument.GetDocReportInfo
set r = ri.Item(i)
getReportInfo = r.Id & "," & r.Name & "," & r.PageCount & CHR(10)
end function
'===================== Function to get the subject etc from variables in document ========
function getVariable(varName)
set v = ActiveDocument.Variables(varName)
getVariable = v.GetContent.String
end function
'===================== Function to get the body etc from texobjects in document ========
function getText(obj)
set mytext = ActiveDocument.GetSheetObject(obj)
prop = mytext.GetProperties
getText = prop.Layout.Text.v
end function
分享到:
相关推荐
You can create an email profile in Express from Tools>Accounts menu. This will open Internet Accounts property sheet. On the tab All, click the button Add and then Mail. A wizard will let you create ...
标题中的“这是一款完整的Visual Basic电子邮件发送客户端”表明这是一个使用Visual Basic编程语言开发的应用程序,其功能是允许用户发送电子邮件。在IT领域,这通常涉及到SMTP(Simple Mail Transfer Protocol)...
Java Sending Email, java Tutorial
标题 "Some java code for sending email" 提供的信息表明,这个压缩包包含了一些用Java语言编写的用于发送电子邮件的代码。描述中的"send me email at : sunjunbin@gmail.com"是作者提供的一种方式,如果你对这些...
在本例中,我们主要关注使用`IMAPI`进行IMAP操作,因为标题提到了`email`、`imap`和`imapi`。 在C#中,由于.NET Framework没有内置对`MAPI`的直接支持,我们需要使用COM Interop来调用Windows的`MAPI`服务。`...
Email Sending Failed(解决方案).md
在给定的标题和描述中提到的"Visual Basic code for Sending email using MAPI control",涉及到的是使用VB通过MAPI(Messaging Application Programming Interface)控件来发送电子邮件的技术。 MAPI是一种在操作...
### Oracle 10g 提示 java.lang.Exception: Exception in sending Request :: null 解决方案 在使用Oracle 10g的过程中,部分用户可能会遇到一个特定的问题:在登录企业管理器(Enterprise Manager, EM)时,系统会...
For example, there are tasks for sending and receiving files through FTP, sending an email, and for accessing a wide range of database management systems. Yet there are times when developers require ...
1. They are sending an email.:这是一个现在进行时的句子,表示他们正在发送电子邮件。 2. We are having a great time.:这句话使用了现在进行时,表示我们正玩得很开心。 3. Who is sending us an email?:这是...
什么是CodeIgniter ... 它的目标是通过提供一组用于执行常见任务的库以及一个简单的界面和逻辑结构来访问这些库,从而使您比从头开始编写代码时更快地开发项目。 CodeIgniter使您可以最大限度地减少给定任务所需的代码...
然而,一些用户在尝试一键boot时可能会遇到“sending boot FAILED”这样的错误,导致刷机过程无法正常进行,窗口瞬间关闭。这通常是由于设备与计算机之间的通信问题,或者是bootloader加载失败所引起的。 为了解决...
【标题】中的“基于C#+ASP.NET实现的Email Sending Web Service服务程序源码”表明了这是一个使用C#编程语言和ASP.NET框架开发的Web服务应用,其主要功能是发送电子邮件。在IT领域,Web服务是一种通过HTTP协议进行...
标题"Sending the contents of a webpage with images as an HTML mail"指的是将网页的完整内容,包括图片,作为HTML格式的邮件发送出去。描述进一步强调了这个主题,即处理网页和其图像的邮件发送过程。接下来,...
IT is a small program which illustrate the concept of sending the file to a remote destination.The concept given in this program is purely for the beginners who just needs to understand the concept ...
使用 MailGun 发送电子邮件 ...git clone https://github.com/Nishkarsh01/Sending-Email-with-MailGun.git 用法 npm install node mail.js 合作 如需合作,请通过我 进一步帮助 有关更多信息,您可以查看:打开
- Email templating and sending emails programmatically. Developers will learn how to create responsive and engaging user interfaces for web applications and services. ### Conclusion "Go in Practice" ...
【标题】"Node.js 发送电子邮件项目"是一个利用Node.js平台和相关库实现电子邮件发送功能的应用实例。在Node.js环境中,我们通常会使用诸如Nodemailer这样的库来处理邮件发送任务,因为它提供了简单且灵活的方式来...
...这两种算法都能有效地减少数据体积,但Gzip通常能提供更好的压缩效果。在ASP.NET中,我们可以通过自定义HttpModule或者使用Response.Filter属性来实现这一功能。 1. **自定义HttpModule** 创建一个自定义...
NULL 博文链接:https://sap.iteye.com/blog/832453