发送时提示输入密码

时间:2015-09-23 10:59:05

标签: vba outlook

我希望Outlook在所有外发邮件中提示输入密码或某种身份验证,因为有人会继续代表我的帐户发送邮件。

我写道:

If Omail.SendUsingAccount = "My Domain Email account typed here" Then

    Sub password()
    Dim pass As String
    pass = InputBox("Enter Password")
    If pass <> "thepassword" Then Exit Sub

End Sub

这不起作用。在我拥有正确的代码之后,我可以将其插入到自定义操作规则中吗?

2 个答案:

答案 0 :(得分:0)

您可以开发一个VBA宏,您可以在其中处理Application类的ItemSend事件,该事件在用户通过Inspector发送Microsoft Outlook项目时触发(在检查器关闭之前,但是用户单击“发送”按钮后)或在程序中使用Outlook项目的Send方法(如MailItem)时。

例如:

Public WithEvents myOlApp As Outlook.Application 

Public Sub Initialize_handler() 
 Set myOlApp = Outlook.Application 
End Sub 

Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean) 
 Dim prompt As String 
 prompt = "Are you sure you want to send " & Item.Subject & "?" 
 If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then 
  Cancel = True 
 End If 
End Sub

您可能会发现Getting Started with VBA in Outlook 2010文章很有帮助。

答案 1 :(得分:0)

请使用以下代码:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
 prompt$ = "Enter Password to Send Mail"

Dim pass As String
    pass = InputBox("Enter Password")
If pass <> "yourpwd" Then
Cancel = True
 End If
End Sub

经过测试,工作正常。

确保您已从信任中心启用了宏。