Accessing COM reference in Wix version

This forum is for discussing Mailtraq's Scripting features. Get help with Mailtraq scripts, templates and external ActiveX scripting.

Re: Accessing COM reference in Wix version

Postby hottroc » Thu Mar 24th, 2011 5:30am

OK thanks for your valued input.

"Could you try calling ConsentLearnMessages() with three parameters? "

OK well done that seems to have done the trick. I can now see the figures changing in the antispam database.Only thing I noticed is the line...

success = mtqmslot.ConsentLearnMessages(filename, False, False)

...seems to be returning -1 rather than zero. But I presume it's OK, I just need to change this:
Code: Select all
If success = 0 Then
                MsgBox("Operation succeeded", , "Success")
            Else
                MsgBox("Something went wrong", , "Failed")
            End If


...to the other way around.


EDIT - Oh one other thing, to teach as NOT SPAM do I change both False args to True in the ConsentLearnMessages statement? EDIT AGAIN - No that doesn't work. ANOTHER EDIT - Never mind, found the answer by experimentation - ConsentLearnMessages(filename, True, False) works fine.

BTW This Remote API seems to work like a dream, much better than the previous API IMHO and I haven't needed any of the tricks I had to employ before. Great work!

So it's all working fine now thanks again for your help. There is one annoying security message that Outlook throws at me about opening attachments from a trustworthy source (to do with the way I have to run the prog from within OL) (EDIT-I've found the solution to this too now) but I can live with that and am a happy man.
Cheers.
hottroc
Expert User
 
Posts: 106
Joined: Tue Jul 24th, 2007 4:23pm

Re: Accessing COM reference in Wix version

Postby Elric Pedder » Fri Mar 25th, 2011 10:46am

It sounds, if I'm following the edits correctly, that you've now got everything working. Is that correct? Does this mean you now have training buttons inside Outlook?
Mailtraq Development and Escalation Support
Novitraq Incorporated
User avatar
Elric Pedder
Mailtraq Escalation Support
 
Posts: 2675
Joined: Tue Nov 23rd, 2004 1:16pm
Location: Montreal, Canada

Re: Accessing COM reference in Wix version

Postby hottroc » Fri Mar 25th, 2011 12:27pm

Elric Pedder wrote:It sounds, if I'm following the edits correctly, that you've now got everything working. Is that correct?


Correct.

Does this mean you now have training buttons inside Outlook?


Correct.

I couldn't have done it without you so I really appreciate your assistance.
hottroc
Expert User
 
Posts: 106
Joined: Tue Jul 24th, 2007 4:23pm

Re: Accessing COM reference in Wix version

Postby Elric Pedder » Sat Mar 26th, 2011 9:09am

I think what you have accomplished would be very interesting for other users. Would you be interested in sharing your script and how you did it?
Mailtraq Development and Escalation Support
Novitraq Incorporated
User avatar
Elric Pedder
Mailtraq Escalation Support
 
Posts: 2675
Joined: Tue Nov 23rd, 2004 1:16pm
Location: Montreal, Canada

Re: Accessing COM reference in Wix version

Postby hottroc » Sat Mar 26th, 2011 4:49pm

Gladly. It's a bit convoluted though but I'll go through it as best I can. Only thing is, it's not a Mailtraq script as such, it's a VB program so would require VS. I'm a bit tied up just now but will try over the next couple of days.
hottroc
Expert User
 
Posts: 106
Joined: Tue Jul 24th, 2007 4:23pm

Re: Accessing COM reference in Wix version

Postby hottroc » Sat Mar 26th, 2011 9:34pm

OK please read these instructions in full and feel free to ask any questions in this topic....


First we need to make an executable file out of the code. In VS I created one small windows form with a single label to use as a status window, named MtqAspam in my code. Set the starting text of the label to "Learning Mail... " Then I added a Module with the code below and set the module as the start-up object.

Code: Select all
Imports Outlook = Microsoft.Office.Interop.Outlook
Module Module1


    Sub Main()
        MtqAspam.Show()
        Dim objApp As Outlook.Application
        Dim objSel As Outlook.Selection
        Dim objItem As Outlook.MailItem
        Dim outmsghead As String
        Dim msgidarray() As String
        Dim msgidno As Integer
        msgidno = 0
        Dim outmsgheadno As Object
        Dim lrnmsg As String
        Dim success As Integer
        Dim myNamespace As Object
        Dim internetHeaders As String
        Dim objCDO As MAPI.Session
        Dim objMessage As MAPI.Message
        Dim objFields As MAPI.Fields
        Dim strID As String
        Const CdoPR_TRANSPORT_MESSAGE_HEADERS = &H7D001E
        lrnmsg = "This will teach the mail system"
        lrnmsg = lrnmsg & " that this message(s) is to be interpreted"
        lrnmsg = lrnmsg & " as GOOD (ie not spam)." 'change this line
        On Error Resume Next
        If (MsgBox(lrnmsg, 49, "Learning to Accept")) = 2 Then Exit Sub 'change this line
        objApp = GetObject(, "Outlook.Application")
        objSel = objApp.ActiveExplorer.Selection
        For Each objItem In objSel
            If objItem.Class = 43 Then
                strID = objItem.EntryID
                objCDO = CreateObject("MAPI.Session")
                objCDO.Logon("", "", False, False)
                objMessage = objCDO.GetMessage(strID)
                objFields = objMessage.Fields
              internetHeaders = objFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Value
                objCDO.Logoff()

                objFields = Nothing
                objMessage = Nothing
                objCDO = Nothing

                outmsghead = ""
                outmsgheadno = 0
              outmsgheadno = InStr(1, internetHeaders, "Message-ID: <", vbTextCompare)
                outmsgheadno = outmsgheadno + 13
                While (Mid(internetHeaders, outmsgheadno, 1)) <> ">"
                    outmsghead = outmsghead & Mid(internetHeaders, outmsgheadno, 1)
                    outmsgheadno = outmsgheadno + 1
                End While
                msgidno = msgidno + 1
                ReDim Preserve msgidarray(msgidno)
                msgidarray(msgidno - 1) = outmsghead
            End If
        Next

        Dim archive As String
        archive = "mailstore" 'name of incoming mail archive,
        Dim mtqapp As Object
        Dim filename As String
        Dim loginsuccess As Long
        loginsuccess = 92
        mtqapp = New MailtraqRemote.Connection
        loginsuccess = mtqapp.Login("localhost", "", "password")
        If loginsuccess = 0 Then
            MtqAspam.Label1.Text += " - OK"
            'MsgBox("Logged in OK")
        Else
            MsgBox("Failed to connect to Mailtraq")
            Exit Sub
        End If
    Dim mtqsvr As Object
    Dim mtqmslot As Object
     mtqsvr = mtqapp.Server.Mailslots.FindByName(archive)
        If (mtqsvr) Then
            mtqmslot = mtqapp.Server.Mailslots.Get(mtqsvr)
        Else
            MsgBox("Problem opening mailslot")
            Exit Sub
        End If
    Dim strarraytemp As String

         For i = 0 To (msgidno - 1)
            strarraytemp = msgidarray(i)
            filename = mtqmslot.FindMessageId(strarraytemp)
           success = mtqmslot.ConsentLearnMessages(filename, True, False) 'change this line
            If success = -1 Then
                MsgBox("Operation succeeded", , "Success")
            Else
                MsgBox("Something went wrong", , "Failed")
            End If
        Next
        objItem = Nothing
        MtqAspam.Hide()
    End Sub


End Module


Make sure you change this line to point to your Mailtraq server with the Mtq admin password:

loginsuccess = mtqapp.Login("localhost", "", "password")

I used "localhost" but you can use an IP address such as "192.168.1.1" or whatever.

Of course if you can be bothered you could enhance the code to add a settings menu or the like. There are also plenty of other opportunities to improve this code to add better error-checking and such. eg I have included the ability to train multiple messages at once if you wish and it works fine but you get a "Success" message box for each one.

Compile and build the code. You should now have the exe file. Rename this as LearnAccept.exe.
Now change the following lines:

lrnmsg = lrnmsg & " as GOOD (ie not spam)." 'change this line
to
lrnmsg = lrnmsg & " as SPAM (ie not good)." 'change this line

and

If (MsgBox(lrnmsg, 49, "Learning to Accept")) = 2 Then Exit Sub 'change this line
to
If (MsgBox(lrnmsg, 49, "Learning to Reject")) = 2 Then Exit Sub 'change this line

and

success = mtqmslot.ConsentLearnMessages(filename, True, False) 'change this line
to
success = mtqmslot.ConsentLearnMessages(filename, False, False) 'change this line

Now compile and build the code again. You should now have another exe file. Rename this as LearnReject.exe.

OK so now you have 2 exe files to teach Mailtraq to either Accept or Reject one or more messages. Copy them somewhere useful.

Next step is crucial. You need to go into the Mailtraq console and add a new mailbox called 'mailstore' (without quotes). Go to the Options menu then Incoming Mail and on the Options tab tick to "Forward a copy of all Incoming Mail" to the mailstore mailbox. This will copy ALL your incoming mail to the mailstore.

I then set the mailstore mailbox to autoexpire messages after a month. This step is optional and has two consequences...1 You will only have duplicate mails kept for a month and 2 You will only be able to train messages up to a month old.

Now we just need to setup Outlook so we have a couple of useful Training buttons. The following works in Outlook 2007 and earlier I think. If anyone wants to try on a later version I'd be interested to know their results....
Start OL and go into your Inbox. Right-click on an empty area of the menu bar and choose Customise. On the Commands tab click the Rearrange Commands button. Click the Toolbars radio button and make sure Standard is in the drop-down list. Highlight the bottom-most entry currently in the list of controls then click the Add button. Choose "Go" in the left hand side (Categories) and "Web Browser" from the right (after scrolling down) and click OK. Now back in the Rearrange Commands dialogue select the newly added "Web Browser" command and click Modify Selection.
Change Name to "&LearnAccept".
Click "Change Button Image" and choose a suitable icon or you can make one of your own like I did (I've got a nice little green tick with OK above it).
Leave Default Style ticked and click Edit Hyperlink, then Open. It's expecting a URL but guess what goes here? Yes navigate to your LearnAccept.exe file and click OK. (Clever, huh?)
Repeat all the above to add a second button with a different icon (perhaps a red cross like mine?) and point it to LearnReject.exe.
Exit all dialogues and you're done!

To test and use:
Make sure you select (not open) at least one message in Outlook before clicking one of the buttons (not sure what happens if nothing is selected). Follow the prompts.

Now that's basically it but you can refine a bit further. Instead of your OL buttons pointing to the executables directly, point them to a shortcut to the file. Within the shortcut you can choose to run minimized. This wont effect anything except you won't see the Command Prompt box while it's running so neater.
Then in Windows 7 there are 2 warnings to tell you not to trust your own grandma or something. To prevent this...first....

Code: Select all
1.Open the registry editor;
Windows Vista: Start-> type; regedit
Windows XP: Start-> Run-> type; regedit
2.Browse to the following location in the registry
•Office 2007
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common
•Office 2010
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common
3.If the Security key already exists under the Common key, then select it.
If it doesn’t exist already then create it via;
Edit-> New-> Key
4.In the Security key create a new DWORD Value via;
Edit-> New-> DWORD Value
Value name: DisableHyperlinkWarning
Value Type: REG_DWORD
Value: 1

When this key is set to 0 or is missing, the security warning will show again.
You might need to restart your computer for changes to take effect.


....then the 2nd warning can be prevented too. You have to temporarily set OutLook to "Run as Administrator" in the Compat settings so you can then uncheck the box to show the warning next time. Then set it back to Normal and no more silly dialogues.

FINISHED! Now you can train your messages direct from your mail client.
Remember - for all those not reading the WHOLE topic, this is for the WIX version of Mailtraq.
hottroc
Expert User
 
Posts: 106
Joined: Tue Jul 24th, 2007 4:23pm

Re: Accessing COM reference in Wix version

Postby Elric Pedder » Tue Mar 29th, 2011 8:24am

Thanks very much for posting this! I'm still trying to find the matching command in Outlook 2010 but if I get to the bottom of it (or if someone else wants to do this in 2010) I'll add some notes.
Mailtraq Development and Escalation Support
Novitraq Incorporated
User avatar
Elric Pedder
Mailtraq Escalation Support
 
Posts: 2675
Joined: Tue Nov 23rd, 2004 1:16pm
Location: Montreal, Canada

Re: Accessing COM reference in Wix version

Postby hottroc » Tue Mar 29th, 2011 10:06am

Sorry I can't really help with that but I did contemplate that in Vis Studio it seemed to be fairly easy to manipulate the ribbon bar for more recent Office progs so could have been easier to add a button programatically that way treating the app as an add-in. I actually went down that road initially but couldn't figure it out for OL 2007 so diverted back to my traditional method.
hottroc
Expert User
 
Posts: 106
Joined: Tue Jul 24th, 2007 4:23pm

Re: Accessing COM reference in Wix version

Postby hottroc » Wed May 15th, 2013 6:18am

Hi,

My add-in has been working fine for 2 years but I just recently have updated the Mailtraq version to 2.17.5.3342 and now these add-ins seem unable to work. They try to work but seem unable to connect to Mailtraq for the training part. Any ideas please?

PS. You will probably need to re-read the whole thread to have a clue what I'm talking about. Sorry.
hottroc
Expert User
 
Posts: 106
Joined: Tue Jul 24th, 2007 4:23pm

Re: Accessing COM reference in Wix version

Postby Elric Pedder » Wed May 15th, 2013 9:47am

Can you confirm that MailtraqRemote is working?

You can do this by creating a test script (call it "test.js") containing the following :-
Code: Select all
var HOST = "127.0.0.1";
var USERNAME = "";
var PASSWORD = "";

if (WScript.Arguments.Length > 2)
{
  HOST = WScript.Arguments(0);
  USERNAME = WScript.Arguments(1);
  PASSWORD = WScript.Arguments(2);
}
else
{
  WScript.Echo("Parameters: HOST USERNAME PASSWORD");
}

var mailtraq = new ActiveXObject("MailtraqRemote.Connection");
var response = mailtraq.Login(HOST, USERNAME, PASSWORD);
if (response == 0)
{
  WScript.Echo("The Domain is " + mailtraq.Server.LocalHost);
}
else
{
  WScript.Echo("Unable to login to " + HOST + " with account " + USERNAME + ", Code " + response);
}

Then execute it with "c:\windows\syswow64\cscript.exe test.js 127.0.0.1 admin password" (setting username and password as appropriate). What do you see?
Mailtraq Development and Escalation Support
Novitraq Incorporated
User avatar
Elric Pedder
Mailtraq Escalation Support
 
Posts: 2675
Joined: Tue Nov 23rd, 2004 1:16pm
Location: Montreal, Canada

Re: Accessing COM reference in Wix version

Postby hottroc » Wed May 15th, 2013 11:35am

Thanks for your reply, I've done your test. It says....

Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
_



...then it just sits there flashing its cursor until I press Ctrl-C.
This seems to correspond to what I see with my custom add-in, it just sits there, presumably waiting for Mailtraq to reply which it doesn't. (though it also sometimes it brings a dialogue box that says "Failed to connect to Mailtraq")
BTW, none of these connection attempts are logged in the Mtq event log and afaik never have been, would be a useful addition for a future version.

Everything else in Mailtraq appears to be working normally such as email, ftp etc
Unfortunately anything that could have changed in the Mailtraq API could have been anytime since my last update which I think was nearly two years ago so might be difficult for you to spot (I've had this problem when updating before if you remember which is why I don't update often....if it ain't broke etc) or could even be related to a Windows update rather than Mtq.
Anyway your investigations would be appreciated.
hottroc
Expert User
 
Posts: 106
Joined: Tue Jul 24th, 2007 4:23pm

Re: Accessing COM reference in Wix version

Postby hottroc » Tue May 21st, 2013 9:33am

Ref: my above post, have you had a chance to check that the MailtraqRemote functions are still working in 2.17.5.3342 ?
Thanks.
hottroc
Expert User
 
Posts: 106
Joined: Tue Jul 24th, 2007 4:23pm

Re: Accessing COM reference in Wix version

Postby Elric Pedder » Tue May 21st, 2013 11:32am

hottroc wrote:Ref: my above post, have you had a chance to check that the MailtraqRemote functions are still working in 2.17.5.3342 ?
Thanks.

I had tested that script without problems against build 3342 prior to posting it and I don't have any idea why it would have stopped working for you. Is it possible for you to expose port 7889 of your Mailtraq server through the firewall and allow me to remote perform the same function?

I should note that MailtraqRemote is the client component of the system. On the server side this is the same system used by the Remote Console, the Mailtraq Monitor and the Outlook Plugin. This suggests any change would be within the MailtraqRemote package or its use and not Mailtraq itself. I should note that using ActiveX controls in this manner is something that Microsoft considers "unsafe" and so it is quite possible that a patch has disabled it. Is it possible for you to run the prior test as an administrator?
Mailtraq Development and Escalation Support
Novitraq Incorporated
User avatar
Elric Pedder
Mailtraq Escalation Support
 
Posts: 2675
Joined: Tue Nov 23rd, 2004 1:16pm
Location: Montreal, Canada

Re: Accessing COM reference in Wix version

Postby hottroc » Tue May 21st, 2013 12:59pm

Elric Pedder wrote:
hottroc wrote:Ref: my above post, have you had a chance to check that the MailtraqRemote functions are still working in 2.17.5.3342 ?
Thanks.

I had tested that script without problems against build 3342 prior to posting it

OK, it's not that then. Strange.
Is it possible for you to expose port 7889 of your Mailtraq server through the firewall and allow me to remote perform the same function?

Sure, but why port 7889, I don't think I've got anything running on that port? Should I have? Oh and also, the steps to achieve this....port forward the port in my router to my Mtq server, then Allow an incoming connection (to what program?) for any ip address in my server?
Actually this has made me remember something. Way back when I started this after switching to the Wix version, I had to change some setting in the registry to allow the remote api to work. It's very vague, do you know what I mean. Just wondered if this might have been reset when I did the update?
EDIT:Actually I just had a look through some of my old emails you sent me from the old dev mailing list and I found this...

"Firstly, you'll need to activate a debug feature in Mailtraq called "RemoteConsole". If you aren't familiar with debug features, here's how you do it:

In the registry, open HKEY_LOCAL_MACHINE\Software\Fastraq\Mailtraq and create a string value named "DebugFlags" with a value of "RemoteConsole=1". If you already have this value, add ",RemoteConsole=1" to it.
"


This was what I was thinking of. Now when I look in Regedit (in the correct syswow64 node) I don't appear to have that key or value, is it still required. Must have been wiped out by the update. Could be causing my entire problem.....
/EDIT

On the server side this is the same system used by the Remote Console, the Mailtraq Monitor and the Outlook Plugin. This suggests any change would be within the MailtraqRemote package or its use and not Mailtraq itself.

Yes.
I should note that using ActiveX controls in this manner is something that Microsoft considers "unsafe" and so it is quite possible that a patch has disabled it. Is it possible for you to run the prior test as an administrator?

Damn Microsoft. Unsafe, pah! Well there have been a lot of ms updates recently that have been to do with vulnerabilities caused by allowing elevation of privilege, which might have something to do with it, hence my remark in my earlier post. But I've tried the test.js script from an Administrative command prompt and it produces the same result.
If the bit in the EDIT section above is the problem you can ignore all the rest of the post :-)
hottroc
Expert User
 
Posts: 106
Joined: Tue Jul 24th, 2007 4:23pm

Re: Accessing COM reference in Wix version

Postby Elric Pedder » Tue May 21st, 2013 1:40pm

That DebugFlag was necessary before the WiX edition was released and now it isn't used any more.

Port 7889 is Mailtraq's Remote control port (which is built into Mailtraq and isn't a service).

Can you run another test? Try a telnet connection to the server on port 7889 and see if you get anything at all.
Mailtraq Development and Escalation Support
Novitraq Incorporated
User avatar
Elric Pedder
Mailtraq Escalation Support
 
Posts: 2675
Joined: Tue Nov 23rd, 2004 1:16pm
Location: Montreal, Canada

PreviousNext

Return to Mailtraq Scripting

Who is online

Users browsing this forum: No registered users and 1 guest

cron