OEAPI: changing message headers in the Oubox folder

1 view
Skip to first unread message

ilena

unread,
Feb 14, 2008, 2:02:37 AM2/14/08
to Nektra OEAPI Support
Hi, Frederico,



I need to implement the next scenario in VB6 for Windows Mail: I need
to add some headers and change html body of the outgoing message.

I tried a few variants of this implementation:



1. Clone the source message to the Outbox folder, make all
needed changers and permanently delete the source message from the
Outbox. In this case I receive the next warning from the Win Mail:
"One or more messages in your Outbox do not have a valid account
specified. Would you like to use your default account to send these
messages?"

The source message stays in the Deleted folder, though I pass
'permanent delete' parameter to the message.delete method.


2. Clone the existing message to the Drafts folder, make all
needed changers, send cloned message and permanently delete source
message from the Outbox(here I use clone.send method ). In this case
the cloned message stays in the Draft folder and the source message
does not disappear from the Deleted Items folder.


3. Use 'Api_OnDatabaseChange' event instead of
'Api_OnNewMessageInOutbox' to make all changes, but I can't catch
source message before it leaves Outbox folder.


This scenario was implemented in Outlook Express and works fine.

I use registered OEAPI v 3.2.1 on Vista Business computer and develop
plugin dll .



Here is a code for Vista, VB6, dll plugin:





Private Sub Api_OnNewMessageInOutbox(ByVal msgId As Long)

On Error GoTo Trapp

Dim oMessage As OEMessage

Dim oOutboxFldr As OEFolder

Dim sAccountID As String

Dim iPos As Long

Dim sAccountsArray As String

Dim bFromPOP3 As Boolean

Dim sUID As String

Dim iMesId As Long



If oFolderManager Is Nothing Then

Set oFolderManager = New OEFolderManager

oFolderManager.ActivateGlobalNotification

End If



Set oOutboxFldr = oFolderManager.GetOutboxFolder

Set oMessage = oOutboxFldr.GetMessage(msgId)



If oMessage Is Nothing Then

Set oOutboxFldr = Nothing

Exit Sub

End If



'check, whether this message is already changed, so do nothing



sUID = GetMesPropByName(oMessage, OTL_UID)



If StrComp(CStr(sUID), vbNullString) <> 0 Then

Exit Sub

End If



bFromPOP3 = True

' if we need to add some properties and change body

iMesId = MailItemSend(oMessage, bFromPOP3)



' delete source message

oOutboxFldr.GetMessage(msgId).Delete 1



Set oMessage = Nothing

Set oOutboxFldr = Nothing

Exit Sub



Trapp:

Set oMessage = Nothing

Set oOutboxFldr = Nothing



End Sub



Public Function MailItemSend(ByVal oMail As OEMessage, bFromPOP3 As
Boolean) As Long

Dim Pos As Long

Dim sTmp1 As String

Dim sTmp As String

Dim sHTMLBody As String

Dim sPrevHtmlBody As String

Dim sParam As String

Dim sInvisUrl As String

Dim sVisibleUrl As String

Dim bIsButtonActive As Boolean

Dim sHTML As String

Dim oClone As OEMessage



'=========OE===========

Dim lBodyHandle As Long

Dim lHTMLBodyHandle As Long

Dim sUserProp As String

Dim exist As Long

Dim lRet As Long

Dim sUsertypeid As String

Dim iMsgId As Long

Dim sSender As String



On Error GoTo Finish





If oFolderManager Is Nothing Then

Set oFolderManager = New OEFolderManager

oFolderManager.ActivateGlobalNotification

End If

Set oClone = New OEMessage

Set oClone = oMail.Clone(oFolderManager.GetOutboxFolder.GetID)

lBodyHandle = oClone.GetBodyHandle(0, OE_IBL_ROOT)

lHTMLBodyHandle = oClone.GetHTMLbody

'sTmp= new html body



oClone.SetBodyText lHTMLBodyHandle, sTmp, "text", "html"

'===================Set custom
properties=================================

lRet = oClone.SetBodyPropByName(lBodyHandle, MESSAGE_TMP_ID,
CStr(iCounter))

lRet = oClone.SetBodyPropByName(lBodyHandle, OTL_UID,
CStr(iUserId))

lRet = oClone.SetBodyPropByName(lBodyHandle, NOTIFY_USER, "1")


'=======================================================================

If oClone.Commit = 1 Then Debug.Print "aaa" 'CStr(oMail.Delete(1))

MailItemSend = oClone.GetID

Exit Function

Finish:



End Function



pls, advise



regards,

Ivchenko Lena,

Speedbit



Nektra OEAPI Support

unread,
Feb 14, 2008, 11:29:08 AM2/14/08
to Nektra...@googlegroups.com
Hi Lena:

The problems is that in Windows Mail the account information is not
stored with each message since Clone only duplicate message that
information is not copied.

You are developing a dll plugin then you should be able to modify the
message within OnNewMessageInOutbox event, before the message is delivered.

I suggest that try the following to make OnNewMessageInOutbox faster
before the message is delivered:
* Create only one global OEFolderManager object.
* Create only one instance of OEFolder for outbox.
* Do not Clone message, modify it while is in outbox.
* Don't call ActivateGlobalNotification, the new events
OnDatabaseChange/OnNewMessageInOutbox don't require it.

Remember to release the global objects when OnShutdownOEAPI event is
called or else WinMail will hang up.

If the problem persist please contact again.

Regards,

Federico

--
Nektra Advanced Computing
http://www.nektra.com

ilena

unread,
Feb 18, 2008, 7:01:10 AM2/18/08
to Nektra OEAPI Support
Hi, Federico,

I followed your instructions and found out that it is impossible to
modify message within OnNewMessageInOutbox event.
I send you a little sample, maybe I missed something. Please advise.


========================================================

Public WithEvents OeInit As OEAPIInit
Public WithEvents Api As OEAPI.OEAPIObj
Public WithEvents oFoldMan As OEFolderManager
Public WithEvents oOutbox As OEFolder


Private Sub Api_OnNewMessageInOutbox(ByVal msgId As Long)
Dim oMes As OEMessage
Dim lBodyHandle As Long, lRet As Long

Set oMes = oOutbox.GetMessage(msgId)
lBodyHandle = oMes.GetBodyHandle(0, OE_IBL_ROOT)
'lRet = oMes.SetBodyProp(lBodyHandle, OE_PID_ATT_PRIORITY, "1")
lRet = oMes.SetBodyPropByName(lBodyHandle, "test", "test-test")
lRet = oMes.Commit
End Sub


Private Sub Class_Initialize()
Set OeInit = New OEAPIInit
Set oFoldMan = New OEFolderManager
Set oOutbox = oFoldMan.GetOutboxFolder
End Sub

Private Sub Class_Terminate()
Set OeInit = Nothing
End Sub

Private Sub OeInit_OnInitOEAPI()
Set Api = New OEAPIObj
End Sub

Private Sub OeInit_OnShutdownOEAPI()
Set Api = Nothing
Set oFoldMan = Nothing
Set oOutbox = Nothing
End Sub
=========================================================================
Lena I.


On Feb 14, 6:29 pm, Nektra OEAPI Support <oeapi-supp...@nektra.com>
wrote:

Nektra OEAPI Support

unread,
Feb 18, 2008, 7:47:01 PM2/18/08
to Nektra...@googlegroups.com
Hi Lena,

Please, Can you send us a sample project ready to compile? We've tried
with a C++ plugin without problems.

Nektra OEAPI Support

unread,
Feb 22, 2008, 4:23:39 PM2/22/08
to Nektra...@googlegroups.com
Hi again Lena:

On your project you should move the setting of oFoldMan and oOutbox
objects to the OeInit_OnInitOEAPI function.
This way it works:

Private Sub Class_Initialize()
Set OeInit = New OEAPIInit

End Sub

Private Sub OeInit_OnInitOEAPI()
Set Api = New OEAPIObj

Set oFoldMan = New OEFolderManager
Set oOutbox = oFoldMan.GetOutboxFolder
End Sub

Private Sub Api_OnNewMessageInOutbox(ByVal msgId As Long)


Dim oMes As OEMessage
Dim lBodyHandle As Long, lRet As Long

Set oMes = oOutbox.GetMessage(msgId)
lBodyHandle = oMes.GetBodyHandle(0, OE_IBL_ROOT)
'lRet = oMes.SetBodyProp(lBodyHandle, OE_PID_ATT_PRIORITY, "1")
lRet = oMes.SetBodyPropByName(lBodyHandle, "test", "test-test")
lRet = oMes.Commit

Set oMes = Nothing
End Sub

Private Sub OeInit_OnShutdownOEAPI()


Set Api = Nothing
Set oFoldMan = Nothing
Set oOutbox = Nothing
End Sub

Private Sub Class_Terminate()


Set OeInit = Nothing
End Sub


Thank you for contacting Nektra's OEAPI Support.

ilena

unread,
Feb 26, 2008, 9:19:52 AM2/26/08
to Nektra OEAPI Support
Hi, Federico,

It does not work.

May be a problem is in the Winmail account configuration? I use Pop3
account on exchange.
Lena



On Feb 22, 11:23 pm, Nektra OEAPI Support <oeapi-supp...@nektra.com>
wrote:

Nektra OEAPI Support

unread,
Feb 28, 2008, 10:32:16 AM2/28/08
to Nektra...@googlegroups.com
Hi Lena:

We had checked this and worked on C++ and on C# but, as you say, it
fails on VB.
We need some more time to make some research about this problem.

Nektra OEAPI Support

unread,
Feb 28, 2008, 4:05:07 PM2/28/08
to Nektra...@googlegroups.com
Hi again Lena:

We have found that the Commit function fails on VB on Debug mode
(Executing from Visual Studio 6), but it succeeds when directly using
the compiled DLL (Release mode), this without changing any code, so it
seems a VB6 Debug mode problem.
Please make the TestOeapiPlugin.dll file and, make sure the required key
is placed on the registry, run Windows Mail and test the DLL's
OnNewMessageInOutbox function.

ilena

unread,
Mar 4, 2008, 5:21:31 AM3/4/08
to Nektra OEAPI Support
Hi, Federico,
Thank you for your assistance.
My plugin dll really works in the release mode.

And one question more: what about OE_PID_ATT_ACCOUNT property number?
How may I know in Vista via what account message is sent.

Regards,
lena

On Feb 28, 11:05 pm, Nektra OEAPI Support <oeapi-supp...@nektra.com>
wrote:

Nektra OEAPI Support

unread,
Mar 6, 2008, 11:19:25 AM3/6/08
to Nektra...@googlegroups.com
Hi Lena:

Windows Mail has a different way to store account information than
Outlook Express.
It no longer uses the OE_PID_ATT_ACCOUNT property, so checking the
account used for a message is not supported on Windows Mail.

Reply all
Reply to author
Forward
0 new messages