Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Stripping selected text fro e-mail

  • 07-03-2006 12:29pm
    #1
    Closed Accounts Posts: 250 ✭✭


    Hi

    I'm looking for some vb code to strip out text from e-mails. Anyone have any links to such code ?

    cheers
    GP


Comments

  • Closed Accounts Posts: 24 Phileas Fogg


    GP wrote:
    Hi

    I'm looking for some vb code to strip out text from e-mails. Anyone have any links to such code ?

    cheers
    GP

    Kinda broad don't ya think ...
    • Do the emails have to be retrieved from a server?
      OR
    • Are they saved to a directory somewhere?
    • If so in what format?
    • What part of the email do you want to strip out?
    • Is this a college assignment? (sounds like one)


  • Closed Accounts Posts: 250 ✭✭GP


    not that broad.

    e-mails come in to Outlook and I want to strip out some text from specific e-mails.

    no it's not a college assignemnt but a personal one.


  • Closed Accounts Posts: 24 Phileas Fogg


    http://www.microsoft.com/office/previous/outlook/supreasy.asp

    Is a good a starting point as any, in fact it's probably better than most. After a quick browse it doesn't seem to say straight out how to retrieve a mail - you need to retrieve a collection of items from a folder and iterate through that. Items can be any folder object be it a mail, appointment or notes. I'd imagine you'll be reading from one of the mail folders so it shouldn't be a problem.


  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    GP wrote:
    e-mails come in to Outlook and I want to strip out some text from specific e-mails.

    Updating the docs can be tricky: do you really mean removing text and updating the docs, or do you mean extracting text for use elsewhere?


  • Closed Accounts Posts: 756 ✭✭✭Zaph0d


    Yeah, what do you want to do with the text once you've stripped it out? Stick it in a database? Write it out to a file? Create a new email?


  • Advertisement
  • Closed Accounts Posts: 250 ✭✭GP


    Going to save it a db.


  • Closed Accounts Posts: 250 ✭✭GP


    Thanks very much, I will check it out.

    http://www.microsoft.com/office/previous/outlook/supreasy.asp

    Is a good a starting point as any, in fact it's probably better than most. After a quick browse it doesn't seem to say straight out how to retrieve a mail - you need to retrieve a collection of items from a folder and iterate through that. Items can be any folder object be it a mail, appointment or notes. I'd imagine you'll be reading from one of the mail folders so it shouldn't be a problem.


  • Closed Accounts Posts: 24 Phileas Fogg


    What email server are you using? You might be able to do it there.


  • Closed Accounts Posts: 756 ✭✭✭Zaph0d


    Here's some code I use on my machine. It requires 'windows script host' to run which you can download for free.

    This code goes through bounced email notifications in my mailbox and stores the bounced email address in my database and then archives the email in question to a folder called BouncedArchive. It needs a table on your database called bounced with fields email and bouncedate.

    You will need to alter the regular expression to match whatever you are searching for. You will need to alter the folder names to whatever your folders are called in Outlook. You will need to set the database connection string to something suitable for your database.

    Also you shouldn't use dynamic sql as I have done because it is the devil's gick.

    Dim o, ns
    Set o=CreateObject("Outlook.Application")
    Set olns=o.GetNameSpace("MAPI")
    
       ' Set the default Bouncebackfolder.	
       Set MyMailbox = olns.Folders("Mailbox - Zaph0d")
       Set MyBounced = MyMailbox.Folders("Inbox")
       Set MyArchive = MyMailbox.Folders("BouncedArchive")
       'Create a regular expression object
       Dim objRegExp
       Set objRegExp = New RegExp
       Dim objMatches, strBody
    	' Create and setup connection object
    	Set objConn = CreateObject("ADODB.Connection")
    	objConn.Open "Provider=sqloledb;Data Source=myDatabaseServerName;Initial Catalog=myDatabase;Integrated Security=SSPI;" 
    
    
    
       ' Loop through each contact.
       Set MyItems = MyBounced.Items
       Do While MyItems.count>0
       ' We need two loops because Outlook skips items as it moves through them.
       For Each SpecificItem in MyItems
    
    	strBody =   SpecificItem.Body
    
    	'Set our pattern
    	objRegExp.Pattern = "\s\S*@\S*\son\s"
    	objRegExp.IgnoreCase = True
    	objRegExp.Global = True
    
    	'Get the matches from the contents of our email body
    
    	Set objMatches = objRegExp.Execute(strBody)
    	if objMatches.count=1 then
    		strEmail = trim(left(objMatches(0).value,len(objMatches(0).value)-3))
    
    	' Store the email address in the database
    
    	objconn.Execute "INSERT INTO bounced (email,bouncedate) VALUES('" & strEmail & "', getdate())"
    	end if
       ' archive the email
       SpecificItem.move MyArchive
    
      Next
    wscript.sleep(3000)
       Set MyItems = MyBounced.Items
    Loop
    


  • Closed Accounts Posts: 250 ✭✭GP


    What email server are you using? You might be able to do it there.

    My mail server is offsite and I will be running this program localy when certain e-mails arrive.


  • Advertisement
  • Closed Accounts Posts: 250 ✭✭GP


    Zaph0d wrote:
    Here's some code I use on my machine. It requires 'windows script host' to run which you can download for free....
    QUOTE]

    Thanks very much. At the moment I have the program checking for new mail in a specific folder and which has the correct subject line and then does something with the e-mail.

    It's all working well and now just need to get the text stripping bit working.

    Thanks for the code and I will check through it and see if hopefully thers something that can help!

    Thanks again
    GP


Advertisement