View Full Version : Solved: Capture the mail as soon as It receives
kbsudhir
12-13-2007, 02:50 PM
Hi All,
Iam capturing a mail attributes of all the mail which comes to my inbox.
I want to automate this. i.e. As soon as mail arrives it attributes should be captured in a database in the access.
Right now I have go and check regularly and run the macro, this lead to duplications of the attributes of teh same mail being stored along with teh new mail. If I can upload the attributes of the mail which I just received then only that mail's attributes will be captured instead of all the mails in the inbox.
Pls let me know how to do this.
Thanks
Sudhir
:help :banghead:
TonyJollans
12-14-2007, 01:12 PM
Can you not do it with a simple rule - run first on all messages received?
kbsudhir
12-15-2007, 12:28 PM
Thanks Tony,
I am able to trigger an event as sson as I get a new mail using NewMail keyword. But my aim to capture the attributes of that mail. But I am not able to do so. Below is the code which I am using, can you please let me know what mistake I am doing or which is the correct way to do it.
Private Sub Application_NewMail()
' Dim Fld_Path As Object
' Set OutApp = Application.GetNamespace("MAPI")
'
' Set Fld_Path = OutApp.Folders("Personal Folders").Folders("Inbox")
'
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Users\SUDHEER\Documents\Trial.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "select * from InboxContents", cn, adOpenStatic, adLockOptimistic
rs.AddNew
rs.Fields("Importance") = MailItem.Importance
rs.Fields("Subject") = MailItem.Subject
rs.Fields("From") = Item.SenderEmailAddress
rs.Fields("SenderName") = Item.SenderName
rs.Fields("To") = Item.To
rs.Fields("CC") = Item.CC
rs.Fields("ReceivedTime") = Item.ReceivedTime
rs.Fields("CreatedTime") = Item.CreationTime
rs.Fields("ModifiedTime") = Item.LastModificationTime
rs.Update
End Sub
Please have a look into it and let me know my mistake.
Thanks fo ryour time Tony.
:bow:
TonyJollans
12-15-2007, 05:36 PM
I'm afraid I know nothing of the NewMail event and it doesn't show any obvious way of obtaining a pointer to the incoming item.
What I meant was to set up a Rule which runs a script for each new mail item received. When you do this, a pointer to the item is passed to the procedure.
Sub CalledFromRule(NewItem as MailItem)
' Now you can access the incoming mail
End Sub
kbsudhir
12-16-2007, 10:19 AM
I think I am about to crack it, still I will try your way also.
And let you about the progress.
Thanks for your valuable time Tony.
Sudhir
kbsudhir
12-16-2007, 12:12 PM
Hi Tony,
I was trying out your way. But I think when a new mail comes it is not going into that procedure only.
What I have done is wrote the same code in the procedure you have provided.
I think I am goofing some thing, what could be that mistake......??????
Thanks
Sudhir
:banghead:
TonyJollans
12-17-2007, 03:15 AM
Have you set up a rule to make the code run?
kbsudhir
12-17-2007, 06:27 AM
Now, I have created a rule called "NewMailAlert" which will give me customized message.
Please guide what should be my next step. Should I create the procedure which you have provided in the below form
Sub NewMailAlert(NewItem As MailItem)
' Now you can access the incoming mail
End Sub
And all the necessary code to capture its attributes in this procedure....????
Sorry if I sound very Silly
Thanks
Sudhir
TonyJollans
12-17-2007, 08:12 AM
Step by step (but please realise that I don't know much abut Outlook).
Create the procedure just as I coded it:
Sub NewMailAlert(NewItem As MailItem)
' Now you can access the incoming mail, for example ....
MsgBox NewItem.Subject
End Sub
Now create a rule - or change your existing one:
Tools > Rules and Alerts > New Rule... (button)
It may be different in other versions but in 2007 you get a wizard.
Select "Check messages when they arrive" under "Start from a blank rule"
Press Next >
Press Next > again
You will be prompted that the rule will run for all messages. Say Yes.
Check the box that says "run a script"
Then at the bottom of the dialog click on "a script"
You will get a popup with a list of available 'scripts'
It should include "NewMailAlert" if you created it correctly
Select it and press OK
Press Next >
Press Next > again
make sure "Turn on this rule" is checked.
Press Finish
Your 'script' ("NewMailAlert") should now run for every message you receive - as coded it will just give you a message. Now you have to put your own code in there instead (something like you posted earlier, I guess)
kbsudhir
12-18-2007, 09:30 AM
Thanks Tony, it is working perfectly.
I have question here; I don't know should I create a new thread for this or not
I want to do the same to all the mails I am sending i.e capturing their attributes. For that how to get a pointer to the mail sent as soon as I click send.
Can I use ItemSend event (I already that out without any success)?
Is there any option to create a rule as Done for incoming mails..???
Thanks for your precious time Tony.
Sudhir
:thumb :bow:
kbsudhir
12-18-2007, 10:44 AM
Hi Tony
I got the solution from one of the threads, where Patrick had recomended to use ItemSend event.
Thanks for your time
Thank you very much
Sudhir
:thumb :bow:
kbsudhir
12-26-2007, 02:08 PM
Hi Tony,
I am facing a peculiar problem here.
The rule is working fine all the mails which I a getting from inside the organization, the ruke is initiating the macro. but as soon as I send a mail from my public id i.e. gmail or hotmail. then the rule is not working, it is not initiating the macro.
Can you please guide me on this......?????????????????????
:dunno :dunno
Thanks
Sudhir
kbsudhir
12-28-2007, 10:43 AM
Hi,
Best way to capture a mail is to use MailEventEx.
It runs in the background without any problem
Sudhir
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.