通过Outlook完全自动发送和回复Excel

Greettings。 这是我的第一篇文章,请耐心等待。

我计划在MS Access中devise一个数据库软件。 我计划这个软件的function之一就是提交文件以供批准。 理想的是从数据库(报表或表单)中点击发送一个预先写好的电子邮件,附件中有一个文件,但是,这个预先写好的电子邮件会有一个链接,写电子邮件,用于快速自动回复/回复,但不使用Outlook的回复。 目标是人们从数据库发送,其他接收,阅读文件,如果批准,点击“自动回复”,Outlook将只是一个“阅读”软件与所有发送在后台完成。

尽pipe我计划使用Access应用程序,但我在Excel中起草了一个示例,以便进行更快速的testing(目标道具用于传递string,以便能够保存string)。 这是迄今为止的代码。

Private Function SendEmailWithOutlook(MessageTo As String, Subject As String, MessageBody As String, myAttachment As String) ' Define app variable and get Outlook using the "New" keyword Dim olApp As New Outlook.Application Dim olMailItem As Outlook.MailItem ' An Outlook Mail item ' Create a new email object Set olMailItem = olApp.CreateItem(0) ' Add the To/Subject/Body to the message and display the message With olMailItem .to = MessageTo .Subject = Subject .BodyFormat = olFormatHTML .HTMLBody = MessageBody .Attachments.Add (myAttachment) .Send ' Send the message immediately End With ' Release all object variables Set olMailItem = Nothing Set olApp = Nothing End Function 

(来自MS站点)

准备和发送代码的函数。

 Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink) Dim myMsg As String If Target.TextToDisplay = "ASK APROVAL" Then Set c = ActiveWorkbook.Sheets(1).Range("E:E").Find(Target.ScreenTip, LookIn:=xlValues) If c Is Nothing Then MsgBox "File Not Found" Exit Sub End If 'Retrieves the file name, stored in a cell to the right of the path myFile = c.Offset(0, 1).Value 'Prepares the file for HTML reading myFile = Replace(myFile, " ", "%20") myMsg = "<HTML><BODY><SCRIPT type=""VBScript"">" & Chr(13) myMsg = myMsg & "FUNCTION SendEmail()" & Chr(13) myMsg = myMsg & "Dim olApp As New Outlook.Application" & Chr(13) myMsg = myMsg & "Dim olMailItem As Outlook.MailItem" & Chr(13) myMsg = myMsg & "Set olMailItem = olApp.CreateItem(0)" & Chr(13) myMsg = myMsg & "With olMailItem" & Chr(13) myMsg = myMsg & ".to = ""firstsender@company.com""" & Chr(13) myMsg = myMsg & ".Subject = ""Approval""" & Chr(13) myMsg = myMsg & ".BodyFormat = olFormatHTML" & Chr(13) myMsg = myMsg & ".HTMLBody = ""<HTML><BODY>The document metioned bellow is approved!<P>" myMsg = myMsg & myFile myMsg = myMsg & "<P>(Auto Response)</BODY></HTML>""" & Chr(13) myMsg = myMsg & ".Send" & Chr(13) myMsg = myMsg & "End With" & Chr(13) myMsg = myMsg & "Set olMailItem = Nothing" & Chr(13) myMsg = myMsg & "Set olApp = Nothing" & Chr(13) myMsg = myMsg & "End Function" & Chr(13) myMsg = myMsg & "</SCRIPT>Dear Boss<P>Attached to this e-mail is a document for your approval. Thanks.<P><BR><a href=""#"" onclick=""SendMail()"">Click for auto response.</a>" myMsg = myMsg & "</BODY></HTML>" SendEmailWithOutlook "approver@company.com", "Approval of Document in Attachment", myMsg, Target.ScreenTip Set c = Nothing End If End Sub 

电子邮件是成功发送的,但返回电子邮件的链接(尽pipe存在)不会在点击时执行任何操作。 那就是问题所在。

从testing中,通过立即窗口中的debugging,发送完整的HTML代码是正确的,每个报价都是正确的。

作为代码的其他选项,我以前尝试了一个简单的JavaScript函数,与“windows.location.href:'mailto:…”,但没有效果。 我尝试的第一件事是通过HTMLbody发送一个FORM,但提交button作为括号中的文本apeared。

我不知道这是否可能,或者如果我的思路是closures的。 所以,感谢一些帮助。 非常感谢。

出于安全原因,脚本无法在电子邮件正文中使用。 此外,电子邮件正文中的链接不是一个好主意,它不会以你想要的方式工作。 相反,您可以考虑开发一个可以安装在远程机器上的插件。 当你得到这样一个电子邮件(你需要得到任何反馈),你可以添加一个function区button到Outlook用户界面,例如, 同意和回复button,除了标准button。 在button的事件处理程序中,您可以添加您可以在收件箱中获得的用户属性。 是否有意义?