How to delete an email address from a contact - outlook

I have written an AppleScript to delete any email address records in Microsoft Outlook that have a facebook.com domain. This is my script:
tell application "Microsoft Outlook"
repeat with eachContact in every contact
set emailList to email addresses of eachContact
repeat with eachEmail in emailList
if address of eachEmail contains "facebook.com" then
delete eachEmail
end if
end repeat
end repeat
end tell
The "delete eachEmail" syntax is incorrect. It throws the following error:
Microsoft Outlook got an error: Can’t make {address:\"contactname#facebook.com\", type:other} into type specifier." number -1700 from {address:"contactname#facebook.com", type:other} to specifier
How should I delete the email address of the contact?

Related

Applescript to extract dates from email to create ical Calendar event

I have only limited understanding of Applescript but wanted to automate every time I recieve an email regarding an event to automatically create an event in calendar. I have set up a rule in Apple Mail to run an Applescript when the email comes from a specific sender.
What I have so far:
using terms from application "Mail"
on perform mail action with messages caughtMessages for rule 'placeholder rule'
repeat with caughtMessage in caughtMessages
try
set theContent to content of caughtMessage
set theSubject to subject of caughtMessage
on error errorString number errorNumber
display dialog errorString
end try
end repeat
set theLocation to "fixed location"
set theStart to ??? Retreive start date from email ???
set theEnd ??? Retreive end date from email ???
tell application "Calendar"
set theCalendar to "QRESERVE TRAININGS"
tell calendar (get theCalendar as text)
make new event with properties {summary:theSubject, start date:theStart, end date:theEnd, location:theLocation, description:theContent}
end tell
end tell
end perform mail action with messages
end using terms from
The date and time that I am trying to retrieve from the email is formatted as such:
Image of Date and Time formatting
I've got how to run the automation as part of a rule in mail and how to create the subsequent calendar event, but no clue how to extract the date and time of the event. Any help would be hugely appreciated!!
I've tried using grep but had no success with that...

Select a type of sender for email with wildcard

I would like to send an email with applescript. This script will be used on a few computers and the email should be sent by a certain type of account containing "mynetwork.com" in the email address.
Is there a way to automatically select the computer email account containing "my network.com" ? Obviously the wildcard * is not working see code below
property faxboxEmail : {"fax#opilbox.com"}
property theNumber : ""
property theContent : ""
property theSender : "*#mynetwork.com"
tell application "Mail"
set newMessage to make new outgoing message with properties {visible:true, subject:theNumber, content:theContent, sender:theSender}
tell newMessage
make new to recipient with properties {address:faxboxEmail}
end tell
end tell
The sender address for accounts in Mac OS X Mail are stored in the sender addresses property in an account. So, technically what you want is something like get account whose email addresses ends with "#mynetwork.com". However, the email addresses property is a simple list, and AppleScript doesn’t have dynamic searches into lists like that.
However, the number of accounts on any personal computer should be fairly small, so looping through them shouldn’t be a problem.
property faxboxEmail : {"fax#opilbox.com"}
property theNumber : "Nine"
property theContent : "Hello, World"
set foundAddress to false
tell application "Mail"
repeat with potentialSender in accounts
tell potentialSender
repeat with potentialAddress in email addresses as list
if potentialAddress ends with "#mynetwork.com" then
set foundAddress to true
exit repeat
end if
end repeat
end tell
if foundAddress then
exit repeat
end if
end repeat
if foundAddress then
set senderName to full name of potentialSender
set senderAddress to senderName & " <" & potentialAddress & ">"
set newMessage to make new outgoing message with properties {visible:true, subject:theNumber, content:theContent, sender:senderAddress}
tell newMessage
make new to recipient with properties {address:faxboxEmail}
end tell
end if
end tell
You may also find it useful to look at the properties of each account, using something like:
tell application "Mail"
--or “account 1”, “account 3”, etc., up to the number of accounts
get properties of account 2
end tell
If you run that and then look in the results pane, you’ll see all of the properties, including the email addresses property. If your script isn’t doing what you expect it to do, post not just the script, but also the values of the property you’re looking at, in this case the email addresses property. You will probably want to use a test computer with fake example.com, example.org, and example.net email addresses, so as not to expose real email addresses to harvesters.
You also may find it easier to build your scripts from the ground up. For example, in this case, you would want to write a script that sends a hard-coded email from a hard-coded sender. Only once that aspect of the script is working, would you want to add the wrinkle about searching for a dynamic sender. This will simplify your programming process by making each task smaller, and will also make it more obvious where the code is going astray.

How to copy a file from a selected message to an outgoing message in outlook through applescript?

I have been trying to figure out how to copy an attachment from an incoming message in outlook to a new outgoing message through applescript.
The code below is what I've got so far, but it's definitely wrong. Outlook throws and error at me stating: "Microsoft Outlook got an error: Can’t make missing value into type file."
tell application "Microsoft Outlook"
-- get the incoming message
set objMessage to item 1 of (get current messages)
set myMessage to make new outgoing message
-- iterate through attachments
-- for each attachment make a new attachment in the message to send identical properties
-- ???
repeat with _attachment in attachments of objMessage
set n to name of _attachment
set ct to content type of _attachment
set f to file of _attachment
set fs to file size of _attachment
tell myMessage
make new attachment with properties {name:n, content type:ct, file:f, file size:fs}
end tell
end repeat
open myMessage
end tell
I've tried a couple of other things, but I can't seem to get at the file property of the incoming messages attachment.
Does anybody have any experience working with files in Outlook and Applescript in this way?
Dylan
It appears that just passing the attachment between messages doesn't work but saving the attachment first and then passing the file name to the file property for the new attachment does.
tell application "Microsoft Outlook"
local mynames, msg1, msg2, saveToFolder, saveAsName
set msg1 to last item of incoming messages
set msg2 to make new outgoing message with properties {subject:"Testing this thing"}
set saveToFolder to POSIX path of (path to desktop)
repeat with atts in attachments of msg1
set saveAsName to saveToFolder & (name of atts)
log saveAsName
save atts in saveAsName
tell msg2
make new attachment with properties {file:saveAsName} -- with properties {file:atts}
end tell
end repeat
open msg2
end tell
Note 1: You will probably want to add logic to remove the files (original attachments) that were saved from the incoming message.
Note 2: Another option would be to find the location of the file from the incoming message and just use that alias instead of saving them first just to add them to the outbound message'

I need to convert an email address to a recipient

Need to convert an email address from Contacts into a recipient in Mail.
tell application "Contacts"
set sendTo to every person's email 1
end tell
tell application "Mail"
set mesg to make new outgoing message
set recipient of mesg to sendTo -- Need to convert here.
set subject of mesg to "A title"
set content of mesg to "A body"
send mesg
end tell
You've got several problems in your code...
When you get "every person's email 1" you get a list of references, not a list of email addresses. To get the actual email address from a reference you get its "value".
sendTo will be a list, so you have to loop over the list and add each address one at a time in mail.
there's different kinds of recipients. You need to use a "to recipient".
Try this:
tell application "Contacts"
set sendToList to value of every person's email 1
end tell
set emailSender to "me#me.com"
set theSubject to "The subject of the mail"
set theContent to "message body"
tell application "Mail"
set mesg to make new outgoing message with properties {sender:emailSender, subject:theSubject, content:theContent, visible:true}
tell mesg
repeat with i from 1 to count of sendToList
set thisEmail to item i of sendToList
if thisEmail is not missing value then
make new to recipient at end of to recipients with properties {address:thisEmail}
end if
end repeat
--send
end tell
end tell

Create Applescript to email a file

I want to have the Apple mail application accept and email from me and then email a file to me. For example, I want to send an email with the subject "#FILE myfile.doc" and have the script trigger because of the #FILE tag in the subject, and then email me back the file called "myfile.doc".
The files will always be in the same path, but it would be nice to be able to specify the path in the script so I can create different ones for different directories.
I know nothing about Applescript and have dabbled in Automator. I only see in Mail that you can trigger an Applescript from a rule. So I don't know if this can be done in Automator.
Please be basic with your responses because I am a newbie to this.
The purpose is to get a file off my computer when I am away.
Thanks,
ROY
You can do it using a mail rule in Mail. Specify your email address as sender and the subject starting with #FILE. Let the mail rule trigger a script like this:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with thisMessage in theMessages
set theSender to sender of thisMessage
set theSubject to subject of thisMessage
if theSubject begins with "#FILE " then
set theAnswer to make new outgoing message with properties {visible:true}
tell theAnswer
try
tell current application
set theFilePathToSend to (POSIX file (text 7 thru -1 of theSubject)) as alias
end tell
set content to "And here is your file: " & rich text 7 thru -1 of theSubject & return & return
tell content to make new attachment with properties {file name:theFilePathToSend} at after the last paragraph
on error errStr
set content to "An error occured: " & return & errStr
end try
set subject to "Re: " & theSubject
make new to recipient at end of to recipients with properties {address:theSender}
send
end tell
end if
end repeat
end tell
end perform mail action with messages
end using terms from
Using the reply-handler didn't work, but the make new outgoing message did! Specify the full path to the file as subject.
Be aware that this IS a security hole! Sender's email addresses can be faked and somebody knowing this can get nearly every file he (or she) wants. You could specify the allowed folders in this script, i.e. if theSubject begins with "#FILE /Users/rbarr/Desktop/Available files/" then or just by adjusting the conditions your mail rule is triggered.
Enjoy, Michael / Hamburg

Resources