A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

extract email from message body



 
 
Thread Tools Search this Thread Display Modes
  #21  
Old May 4th 07, 02:01 AM posted to microsoft.public.outlook.program_vba
ed
external usenet poster
 
Posts: 114
Default extract email from message body

Tried InStr and AdvancedSearch. the latter requries a whole second routine
to catch the results of the search, but I'm not sure it is capable of
capturing from a MAPI file. This works, but I can't figure out how to
capture the result:

Dim objSch As Search
Const strF As String = "urn:schemas:httpmail:textdescription LIKE '%'"
Const strS As String = "undeliverables"
Const strTag As String = "GITem"
Set objSch = Application.AdvancedSearch(Scope:=strS, _
Filter:=strF, Tag:=strTag)

I cannot figure out how to get the InStr function to return anything but a
boolean (false).

sorry if I confused some terminology.

"Edward" wrote:

Can anyone suggest the best way to open each file in an OUtlook subdirectory
and extract an email address from the body of the email? I have mail coming
back as undeliverable, and want to prune those addresses from our lists, but
the address to which the email was sent is not the same as the return
address, which is usually an automated responder from a mail server that
can't find the address in to:

Basically, I'm trying to write code that will say:
go to the undeliverables subdirectory in Outlook;
for each email, check the body of the email for any/all email address(es)
append the email address to a text file;

--
Phantom Researcher

Ads
  #22  
Old May 4th 07, 06:39 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default extract email from message body



Why don't you try the sample for AdvancedSearch that I gave you with my last
post? Your code doesn't work, that's right.

if you prefer to loop through all of the items and search with Instr: That
function returns the postion of the found string - if any. Then you must use
the Left and/or Right functions to get the string left and/or right side
from that position.

As it's hard to follow the thread you messed up totally, here's a sample for
a loop in *principle*:

Dim obj as Object
Dim Items as Outlook.Items
Dim Folder as Outlook.Mapifolder
Dim i as Long
Dim Pos1 as Long,Pos2 as Long
Dim SLeft as String, SMiddle as String, SRight As String

Set Folder=Application.Session.GetDefaultFolder(olFold erInbox)
Set Items=Folder.Items
For i=1 to Items.Count
Set obj=Items(i)
Pos1= Instr(1,obj.Body,"whatever",vbTextCompare)
If Pos10 Then
' "whatever" is found
Pos2=pos1+Len("whatever")
' get the text left hand from the searched phrase
SLeft = Left$(obj.Body,Pos1-1)
' get the text right hand from the searched phrase
SRight = Mid$(obj.Body,Pos2+1)
' get the text searched phrase itself
SMiddle = Mid$(obj.Body,Pos1,Pos2+1-Pos1)
Endif
Next

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - Categorize Outlook data:
http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Thu, 3 May 2007 18:01:01 -0700 schrieb Ed:

Tried InStr and AdvancedSearch. the latter requries a whole second

routine
to catch the results of the search, but I'm not sure it is capable of
capturing from a MAPI file. This works, but I can't figure out how to
capture the result:

Dim objSch As Search
Const strF As String = "urn:schemas:httpmail:textdescription LIKE

'%'"
Const strS As String = "undeliverables"
Const strTag As String = "GITem"
Set objSch = Application.AdvancedSearch(Scope:=strS, _
Filter:=strF, Tag:=strTag)

I cannot figure out how to get the InStr function to return anything but a
boolean (false).

sorry if I confused some terminology.

"Edward" wrote:

Can anyone suggest the best way to open each file in an OUtlook

subdirectory
and extract an email address from the body of the email? I have mail

coming
back as undeliverable, and want to prune those addresses from our lists,

but
the address to which the email was sent is not the same as the return
address, which is usually an automated responder from a mail server that
can't find the address in to:

Basically, I'm trying to write code that will say:
go to the undeliverables subdirectory in Outlook;
for each email, check the body of the email for any/all email address(es)
append the email address to a text file;

--
Phantom Researcher

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I modify the message body displayed in the email window? Steffen Heinzl Add-ins for Outlook 4 November 10th 06 10:49 AM
Email font size in body changes randomly after the message is sent [email protected] Outlook - General Queries 0 May 31st 06 10:52 PM
Help: Send To Email Message in Body TJ Outlook Express 3 May 4th 06 01:23 PM
Attachment does not show on header but in message body when create new email Johnny Chow Outlook - General Queries 2 January 30th 06 11:47 PM
How to filter email with blank subject, to, and message body ken4az Outlook - Installation 0 January 20th 06 06:27 PM


All times are GMT +1. The time now is 11:24 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.