Extract Contact Info from web form in body of emails

Sure here you go

replyToSubmitterMail.workflow.zip

Is there a way to get this to work with Outlook 2011?

I just remembered I do have outlook 2010 on my Laptop.

But firstly before I go to lengths looking at outlook how did it work for you in Mail.app.
Cheers

I don’t use mail - I have 15 years of data in entourage and now outlook 2011 for mac

I tried it in mail and it seemed to work ok.

Ok.

In Outlook 2010 the conversion is easy; all except changing the to recipient.
And I had to add a filter on the return email extraction.

So for the Outlook workflow. I have made it appear that it is a reply that pops up but it is actually a new message with all the ingredients of a reply.

My assumption is that the messages are not plain text but the default html.

UPDATED 17Nov2012 12:10 gmt
download:
replyToSubmitterMailOUTLOOK2010v2.workflow.zip

And here is how the workflow is structured.

1, Run Appliscript

tell application "Microsoft Outlook"
	set theMessage to item 1 of (get selection)
	set theBody to content of theMessage
end tell
set AppleScript's text item delimiters to ""
set AppleScript's text item delimiters to "mailfrom:"

set theBody to text item 2 of theBody
set AppleScript's text item delimiters to ""
return theBody

2, Extract email address from Text

set to Extract : email addresses

3, Filter Paragraphs

Return Paragraphs that: do not begin with mailto:

4, Run Appliscript

on run {input, parameters}
	set text_returned to item 1 of input
	--set text_returned to (choose from list input with prompt "Choose address" default items "" without multiple selections allowed and empty selection allowed)
	if text_returned is not false then
		tell application "Microsoft Outlook"
			set t to item 1 of (get selection)
			set recip to email address of to recipient of t
			set theFrom to address of item 1 of recip
			set theRecDate to time sent of t
			set subj to subject of t
			
			set body to "<br><br><span id=\"OLK_SRC_BODY_SECTION\"><div style=\"font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt\">
	
	
	From: " & quoted form of text_returned & "
<br>Date: " & theRecDate & "
<br>To: " & theFrom & "<br>Subject: " & subj & "



<p>" & content of t & "</p>"
			set newMessage to make new outgoing message with properties {subject:("RE: " & subj as string), content:body}
			make new recipient at newMessage with properties {email address:{name:"", address:text_returned}}
			open newMessage
		end tell
	end if
end run

Nice. Thank you very much.
I have installed it into the services menu, but don’t know how to access that via outlook.
Or, do I have to run automater each time I want to run the script?

It Appears that it is actually quit easy.

While in Outlook, You should see a script menu icon in the menu bar after the Help menu.
Click it and got to About this Menu.
Read the info so you understand what is going on. Then click the button to 'Open Folder".

Put a copy of the workflow in the folder. (You do not have to put it in the Sample Folder that in there.)
Close the folder.
Go back to Outlook.
Select a message.

Go to the Script menu and select the workflow.

I must need to rename it or something. I can get it into the folder, but it won’t run.
I put this into the folder: replyToSubmitterMailOUTLOOK2010.workflow
I changed it to OUTLOOK2011 because that’s the version I’m running.

It does run in automater, but not in the script menu.

Also, instead of creating a reply email, can the script be setup to open a new contact and add the email address and name to the contact page? I would also like it to somehow attach the incoming email to the contact page for future reference.

Thanks so much for your great help.

I was able to save it as an application and use it that way.

Here is the format of the messages when they come into outlook:

sendtoemail: william@williammorrisstudio.com
name: Tootsie Roll
address: 1716 Ellie Ct
citytown: Benicia
statezip: CA 94510
mailfrom: tootsie@tootsieroll.com
telephone:
foundus: american bungalow
galleryname:
Lamp_1: Briggs
textareaName: Please type your message here.
submitButtonName: Submit

This e-mail was generated from a form submission on your website.

Is there a way to input the information from the form above into a new contact with the name, address, phone number and email address?

Having the content you receive helps.

I have UPDATED the above Post to fix some errors ( from and to email placement) and also redone the workflow. You do not get the dialogue any more as I can filter the mail from: now.

replyToSubmitterMailOUTLOOK2010v2.workflow.zip

I suspect the reason why it will not work from your Outlook script menu is because you removed the .worflow extension.

Doing this makes your Mac think the workflow is a folder. Automator Workflows are packages (folders) put must have the .workflow extension to tell the system it is to be treated as such and not a folder.

As to the contacts part.

What have you tried. :slight_smile:

Mark,
It appears that the workflows in outlook 2011 have an added character to the naming convention.
Below are the workflows included with outlook and the Contact Reply workflow you created.
What happens when I run the workflow in outlook is nothing. But the menu then gets grayed out and I have to restart outlook to make the menu active again.

Anyway, I can run it as a application - I just keep it in the dock and run it that way. Thanks for the update, it works seamlessly.

The contact workflow is something I’ve always wanted. I have thousands of contacts in outlook and inputed all of them manually from the contact form from my website.

Contact Reply.workflow
Convert message text to audio and send to an iPod\sc-.workflow
Create a .zip archive for specified messages\scl.workflow
Edit selected contacts\scn.workflow
Edit specified contacts\sco.workflow
Flag selected messages for follow-up\scs.workflow
Print selected messages\scq.workflow
Send image attachments to iPhoto\sct.workflow
Send images on the current Safari Web page in a message\scw.workflow
Send specified images in a message\scg.workflow
Send the current Safari Web page URL in a message\scu.workflow
Send the system profile in a message\scp.workflow

Ok here you go. since you seemed to have missed my subtle little nudge that you do need to try and work out some of this yourself.

If you need any adjustments please try and figure it out first before asking. We like to help but not always to do it all for you… :slight_smile:



set name_ to {"name: ", ""}
set address_ to {"address: ", ""}
set citytown_ to {"citytown: ", ""}
set statezip_ to {"statezip: ", ""}
set mailfrom_ to {"mailfrom: ", ""}
set telephone_ to {"telephone: ", ""}
set foundus_ to {"foundus: ", ""}
set galleryname_ to {"galleryname: ", ""}
set Lamp_1_ to {"Lamp_1: ", ""}
set textareaName_ to {"textareaName: ", "textareaName: "}
set store to {name_, address_, citytown_, statezip_, mailfrom_, telephone_, foundus_, galleryname_, Lamp_1_, textareaName_}

tell application "Microsoft Outlook"
	set theMessage to item 1 of (get selection) # get the first email message
	set theBody to (plain text content of theMessage) # get plain text message content
end tell


# we are now going to break the content into paragraphs.

# set the delimiters to the carrige return used in outlook. This is \r instead of \n
set AppleScript's text item delimiters to ""
set AppleScript's text item delimiters to return

#get the seperated items.  
set newPara to text items of theBody
# set the delimiters to their normal setting
set AppleScript's text item delimiters to ""

#we are now going to iterate through each variable item listed in the store list. We will access its item values
repeat with i from 1 to number of items in store
	#get the first item of an item in store i.e  from {"name: ", ""}  we get  "name: "
	set this_item to item 1 of item i of store
	
	#we are now going to iterate through each paragraph item in the new newPara list
	repeat with z from 1 to number of items in newPara
		#get an item in newPara  . i.e "name: Tootsie Roll"
		set this_para to item z of newPara
		
		#we check to see if the newPara item contains the store item. i. e,  does "name: Tootsie Roll" contain "name: "
		if this_para contains this_item then
			# if it does then we set the delimiters to the store item  i.e "name: "
			set AppleScript's text item delimiters to this_item
			#now we get the item to the left of the split. i.e  from "name: Tootsie Roll" we get 'Tootsie Roll".
			# note is there was text on the other side of the delimiter("name: ") we would call it text item 1
			
			
			#now we set the second item of the item in the store item to the value of text item 2. i.e where we had {"name: ", ""}  we  will now have {"name: ", "Tootsie Roll"} 
			set item 2 of item i of store to text item 2 of this_para
			
			
			# set the delimiters to their normal setting
			set AppleScript's text item delimiters to ""
			#exit this sub loop as their is no need to test further. we can now go back to the start of the first  repeat loop and pick up the next item in the store items
			exit repeat
		end if
		
		
	end repeat
	
end repeat

#we are now out of the repeat loops and should have all our info ready to use stored in the store items.


# we now make sure the note field is only filled with worthy text.
if item 2 of textareaName_ contains "Please type your message here." then
	set item 2 of textareaName_ to ""
end if

#we now get the first name 
set theFirstName to word 1 of item 2 of name_ as string
#we now get the surename/s 
set theLastName to characters -1 thru word 2 of item 2 of name_ as string

#now we write it all out using the new second items of the variables
tell application "Microsoft Outlook" to make new contact with properties {first name:theFirstName, last name:theLastName, business street address:item 2 of address_, business city:item 2 of citytown_, business zip:item 2 of statezip_, email addresses:{{address:item 2 of mailfrom_, type:work}}, phone:item 2 of telephone_, custom field one:item 2 of foundus_, company:item 2 of galleryname_, custom field two:item 2 of Lamp_1_, note:item 2 of textareaName_}



slight update…

For some reason the carriage return in the lines.

set the delimiters to the carrige return used in outlook. This is \r instead of \n

set AppleScript’s text item delimiters to “”
set AppleScript’s text item delimiters to "
"

is being change to \n by this site. so when you open the script. change it to

set the delimiters to the carrige return used in outlook. This is \r instead of \n

set AppleScript’s text item delimiters to “”
set AppleScript’s text item delimiters to “\r”

I will sort this when I get a min. but have to go out now…

UPDATE.

This is fixed now and the script above updated. no need to do any changes.

AppleScript has a few built-in text constants for control characters

tab (ASCII 9 = \t)
linefeed (ASCII 10 = \n)
return (ASCII 13 = \r)

and for two printable characters

space (ASCII 32)
quote (ASCII 34)

Thanks Stefan,

I wil incorporate that when I get a mo.
:slight_smile:

Thanks Mark.
I was going to ask where one learns how to write the scripts.
Do you have a resource that you would recommend?
William

UPDATE.

The carriage return is fixed now and the script above updated. no need to do any changes.

Part of my job means I have lots of finder windows open on two screens And have to open the same windows everyday. They are windows to network shares which I monitor for new files.
I also had other people who needed the same networks and windows displayed.
Each window had its own place and size on the screens.
Tedious…

So I got into learning Applescript out of necessity. And wrote a script that mounted the volumes associated with the windows then open, size and position them.
That script was my first.
Normally you first is something like

display dialog "Hello World!" buttons {"OK"} default button 1

I have id and am still doing most of my learning by following this forum like this. And using it to pick at code and issues others have. I see if I can work them out for myself, much the same as I have done for you here.

I do have some books but have not used them much. So cannot really recommend them.

I suggest you read the official Apple Introduction to AppleScript overview

This will be a good starting point. And pick a simple task that you want to automate. It does not have to be something you will use in the real would but having a goal helps by stopping you going off on too many tangents and nothing to show for it.

You can also look at the Tutorials for Beginning Scripters over at the unScripted part of this site which has tons of tutorials and examples

Mark,
Thanks for the resources.
For some reason the script doesn’t work in outlook.
I tried it both as an application from the desktop and loaded it into the folder and ran it from the script library in outlook.
I have the email selected and then play the script, but it doesn’t do anything.
The other scripts are working - create a note or a task from the email.
I wonder does every line in the form have to be filled out?
Often people don’t fill out the entire form.
Sorry for all the trouble.

Thats very odd. It is working fine on my mac from the script menu.

1, Does the script work when run in Applescript Editor

2,
If you have not already enabled the Applescript Editor script menu for Applescripts.
Then open the Apple Script Editor’s preferences.
Check (tick) the Show Script menu in menu bar .

A new menu bar item will appear. Which will look like the script menu in Outlook.

Click the Script menu and Navigate to :Open Script folder->Open Users Script folder

Place the Script in the Users Script folder that opens up.
Now when you click the Script menu. You will see the script listed in the Script items.
Just select it and it will run.

Does it work from here.

No they do not.