2014-04-30 107 views
0

我想發出一個自定義的電子郵件通過「規則和通知」在Outlook 2007中通過宏發送電子郵件在「規則和通知」

Sub SpirentBoxcarEmail() 

Dim objOutlook As Object 
Dim objOutlookMsg As Object 

Set objOutlook = CreateObject("Outlook.Application") 
Set objOutlookMsg = objOutlook.CreateItem(0) 

With objOutlookMsg 
    .To = "[email protected]" 
    .Subject = "Test" 
    .Body = "Test" 
    .Send 
End With 

Set objOutlookMsg = Nothing 
Set objOutlook = Nothing 
End Sub 

我知道我需要補充一些像「項目如Outlook。 MailItem'放入子標題的()中,以便在'腳本'下顯示的宏

但是,我是否真的需要爲此「項目」分配任何內容?

宏沒有添加'item'就運行得很好,但是一旦我添加'item As Outlook.MailItem'並且規則執行腳本(宏),電子郵件就不會被髮送出去。

回答

0

很奇怪,用我收到的消息規則工作。你能在程序中設置一個斷點,看看這個腳本是否正在執行?

0

我認爲outlook正在尋找特定的函數簽名。規則期望將當前郵件傳遞給宏。嘗試這個。

Sub SpirentBoxcarEmail(ByRef t As MailItem) 

Dim objOutlook As Object 
Dim objOutlookMsg As Object 

Set objOutlook = CreateObject("Outlook.Application") 
Set objOutlookMsg = objOutlook.CreateItem(0) 

With objOutlookMsg 
    .To = "[email protected]" 
    .Subject = "Test" 
    .Body = "Test" 
    .Send 
End With 

Set objOutlookMsg = Nothing 
Set objOutlook = Nothing 
End Sub 
0

您已經編寫了RunAScript代碼,就好像它不依賴於正在接收的項目一樣。

打開的MailItem和運行SpirentBoxcarEmail_RunAScript_Test

Sub SpirentBoxcarEmail_RunAScript(item As mailitem) 

'Dim objOutlook As Object 
'Dim objOutlookMsg As Object 

Dim objOutlookMsg As mailitem 

' Normally the trigger item is processed in some way. 

MsgBox "The subject of the received mail that triggered the script is: " & _ 
    vbCr & vbCr & item.Subject 

' In this case the trigger item will now be ignored. 

'Set objOutlook = CreateObject("Outlook.Application") 
Set objOutlookMsg = CreateItem(0) 

With objOutlookMsg 
    .To = "[email protected]" 
    .Subject = "Test" 
    .body = "Test" 
    .Send 
End With 

Set objOutlookMsg = Nothing 
'Set objOutlook = Nothing 
End Sub 


Private Sub SpirentBoxcarEmail_RunAScript_Test() 

' Open mail that fulfills the conditions of the rule 
' This simulates mail being received 

Dim currItem As mailitem 
Set currItem = ActiveInspector.currentItem 
SpirentBoxcarEmail_RunAScript currItem 

End Sub