D
Dhananjay
Hello Forum,
I am writing my COM-Addin from VB 2005 for office XP. Now as ItemSent
event's cancel is not working for office XP (http://
support.microsoft.com/kb/830519,) I have written the code for helper
class in my Connect class (Shared Addin's connect class). Now my
ItemSent event's Cancel is working perfectly.
But main thing is that, I am cancelling the ItemSend and I am
writing my code to create my custom mailitem in ItemSend event,
filling that custom mailitem with some properties & saving that
mailitem in SentItems folder (without actually sending it).
My code snippet is as follows -
' This is my button on the explorer that opens a custom mailitem
Private Sub cmdBarButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As
Boolean) Handles cmdBarButton.Click
Try
MyMailItem =
TryCast(myOut.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Items.Add(myCustomForm),
MailItem)
Catch ex As System.Exception
MsgBox("Exception while creating mailitem - " &
ex.Message)
End Try
If MyMailItem IsNot Nothing Then
MyMailItem.To = "(e-mail address removed)"
Try
MyMailItem.Display()
Catch ex As System.Exception
MsgBox ("Exception while displaying the form - " &
ex.Message)
Marshal.ReleaseComObject(MyMailItem)
MyMailItem = Nothing
End Try
Else
MsgBox ("Mail item can not be initialized")
End If
MyMailItem = Nothing
End Sub
'And This is my ItemSend event
<DispId(61442)> _
Public Sub ItemSend(ByVal Item As Object, ByRef Cancel As Boolean)
If TypeOf Item Is MailItem Then
If Item.MessageClass.ToUpper.ToString =
myCustomForm.ToUpper.ToString Then
Cancel = True
MyMail = Item
SendMailInBackground(MyMail)
End If
End If
End Sub
And in SendMailInBackground() procedure I am just creating a Sentitem
mail.
I get Exception - "The operation failed due to a registry or
installation problem. Restart Outlook and try again. If the problem
persists, please reinstall." at the line MyMailItem.Display()
Also some times I am getting the error "DisconnectedContext was
detected" at the line MyMailItem =
TryCast(myOut.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Items.Add(myCustomForm),
MailItem)
Please help me.
Thanks in advance,
Dhananjay
I am writing my COM-Addin from VB 2005 for office XP. Now as ItemSent
event's cancel is not working for office XP (http://
support.microsoft.com/kb/830519,) I have written the code for helper
class in my Connect class (Shared Addin's connect class). Now my
ItemSent event's Cancel is working perfectly.
But main thing is that, I am cancelling the ItemSend and I am
writing my code to create my custom mailitem in ItemSend event,
filling that custom mailitem with some properties & saving that
mailitem in SentItems folder (without actually sending it).
My code snippet is as follows -
' This is my button on the explorer that opens a custom mailitem
Private Sub cmdBarButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As
Boolean) Handles cmdBarButton.Click
Try
MyMailItem =
TryCast(myOut.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Items.Add(myCustomForm),
MailItem)
Catch ex As System.Exception
MsgBox("Exception while creating mailitem - " &
ex.Message)
End Try
If MyMailItem IsNot Nothing Then
MyMailItem.To = "(e-mail address removed)"
Try
MyMailItem.Display()
Catch ex As System.Exception
MsgBox ("Exception while displaying the form - " &
ex.Message)
Marshal.ReleaseComObject(MyMailItem)
MyMailItem = Nothing
End Try
Else
MsgBox ("Mail item can not be initialized")
End If
MyMailItem = Nothing
End Sub
'And This is my ItemSend event
<DispId(61442)> _
Public Sub ItemSend(ByVal Item As Object, ByRef Cancel As Boolean)
If TypeOf Item Is MailItem Then
If Item.MessageClass.ToUpper.ToString =
myCustomForm.ToUpper.ToString Then
Cancel = True
MyMail = Item
SendMailInBackground(MyMail)
End If
End If
End Sub
And in SendMailInBackground() procedure I am just creating a Sentitem
mail.
I get Exception - "The operation failed due to a registry or
installation problem. Restart Outlook and try again. If the problem
persists, please reinstall." at the line MyMailItem.Display()
Also some times I am getting the error "DisconnectedContext was
detected" at the line MyMailItem =
TryCast(myOut.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Items.Add(myCustomForm),
MailItem)
Please help me.
Thanks in advance,
Dhananjay