Sending an Email in Qlikview

'========================= 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

 

内容概要:文章详细介绍了ETL工程师这一职业,解释了ETL(Extract-Transform-Load)的概念及其在数据处理中的重要性。ETL工程师负责将分散、不统一的数据整合为有价值的信息,支持企业的决策分析。日常工作包括数据整合、存储管理、挖掘设计支持和多维分析展现。文中强调了ETL工程师所需的核心技能,如数据库知识、ETL工具使用、编程能力、业务理解能力和问题解决能力。此外,还盘点了常见的ETL工具,包括开源工具如Kettle、XXL-JOB、Oozie、Azkaban和海豚调度,以及企业级工具如TASKCTL和Moia Comtrol。最后,文章探讨了ETL工程师的职业发展路径,从初级到高级的技术晋升,以及向大数据工程师或数据产品经理的横向发展,并提供了学习资源和求职技巧。 适合人群:对数据处理感兴趣,尤其是希望从事数据工程领域的人士,如数据分析师、数据科学家、软件工程师等。 使用场景及目标:①了解ETL工程师的职责和技能要求;②选择适合自己的ETL工具;③规划ETL工程师的职业发展路径;④获取相关的学习资源和求职建议。 其他说明:随着大数据技术的发展和企业数字化转型的加速,ETL工程师的需求不断增加,尤其是在金融、零售、制造、人工智能、物联网和区块链等领域。数据隐私保护法规的完善也使得ETL工程师在数据安全和合规处理方面的作用更加重要。
### 回答1: 可以使用 Python 的 smtplib 模块来发送电子邮件。首先,需要准备好要发送的电子邮件的内容,包括发件人地址、收件人地址、主题和正文。然后,使用 smtplib 模块的 SMTP 类来连接到 SMTP 服务器,并使用 login() 方法登录。接着,使用 sendmail() 方法来发送电子邮件。最后,使用 quit() 方法来断开与 SMTP 服务器的连接。 例如,下面是一段示例代码,展示了如何使用 Python 发送一封简单的电子邮件: ```python import smtplib # 要发送的电子邮件内容 from_addr = 'sender@example.com' to_addr = 'receiver@example.com' subject = 'Test Email' body = 'This is a test email sent from Python.' # 连接到 SMTP 服务器 smtp_server = smtplib.SMTP('smtp.example.com') # 登录到 SMTP 服务器 smtp_server.login('username', 'password') # 构造电子邮件 msg = f'Subject: {subject}\n\n{body}' # 发送电子邮件 smtp_server.sendmail(from_addr, to_addr, msg) # 断开与 SMTP 服务器的连接 smtp_server.quit() ``` 注意,在上面的代码中,需要替换 `sender@example.com` 和 `receiver@example.com` 为实际的发件人地址和收件人地址,并替换 `smtp.example.com` 为实际的 SMTP 服务器地址。此外,需要替换 `username` 和 `password` 为登录 SMTP 服务器的用 ### 回答2: 使用Python发送电子邮件,你可以使用SMTP(简单邮件传输协议)库。 首先,你需要导入smtplib库,以便与SMTP服务器进行通信。然后,创建一个SMTP对象,并登录到你的电子邮件帐户。你需要提供SMTP服务器的主机名和端口号,以及你的电子邮件地址和密码。 接下来,你可以通过调用sendmail()方法来发送邮件。你需要提供发件人,收件人和邮件内容。邮件内容可以通过构建一个MIMEText对象来实现。 以下是一个简单的示例代码,演示如何向一个收件人发送电子邮件: ```python import smtplib from email.mime.text import MIMEText def send_email(): sender = 'example@example.com' receiver = 'example2@example.com' subject = 'Hello from Python' body = 'This is a test email.' msg = MIMEText(body) msg['Subject'] = subject msg['From'] = sender msg['To'] = receiver smtp_server = 'smtp.example.com' smtp_port = 587 username = 'your_username' password = 'your_password' server = smtplib.SMTP(smtp_server, smtp_port) server.starttls() server.login(username, password) server.sendmail(sender, receiver, msg.as_string()) server.quit() send_email() ``` 在上面的示例中,你需要将示例电子邮件地址,SMTP服务器和登录凭据替换为你自己的信息。 这只是一个简单的示例,你可以根据自己的需求进行进一步的定制,比如添加附件、使用HTML格式的邮件等。 总之,使用Python发送电子邮件是非常简单的,只需要使用Python的smtplib库和MIMEText对象即可实现。 ### 回答3: 使用Python发送电子邮件非常简便和方便。下面是一个基本的步骤。 首先,需要导入smtplib和email模块,分别用于发送邮件和构造邮件。可以使用以下代码导入这些模块: ``` import smtplib from email.mime.text import MIMEText ``` 然后,需要配置SMTP服务器的信息,包括SMTP服务器地址、端口号和认证信息。例如,如果使用Gmail作为SMTP服务器,可以使用以下代码进行配置: ``` smtp_server = 'smtp.gmail.com' smtp_port = 587 username = 'your_email@gmail.com' password = 'your_password' ``` 接下来,可以构造邮件内容。例如,可以使用MIMEText对象创建一个简单的纯文本邮件: ``` message = MIMEText('This is the email content.', 'plain') message['From'] = 'sender@example.com' message['To'] = 'receiver@example.com' message['Subject'] = 'Email Subject' ``` 如果要发送HTML格式的邮件,可以将'MIMEText'改为'MIMEText(html_content, 'html')',其中'html_content'是包含HTML内容的字符串。 最后,使用smtplib模块发送邮件。可以使用以下代码发送邮件: ``` with smtplib.SMTP(smtp_server, smtp_port) as server: server.starttls() server.login(username, password) server.send_message(message) ``` 在这个例子中,首先使用starttls()方法启用TLS加密连接,然后使用login()方法进行身份验证,并最后使用send_message()方法发送邮件。 以上就是使用Python发送电子邮件的基本步骤。根据需要,还可以添加更多的功能,例如添加附件或发送多个收件人。参考Python文档以了解更多细节和选项。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值