I am trying to respond back to email and want to include the first name of the person I am responding to based on the known fact that their email is first.last#company.com.
Here is what I have so far but cannot seem to get the email address or name:
on run
tell application "Microsoft Outlook"
set replyToMessage to selection
if (replyToMessage is "") then
-- no email selected, don't continue
display dialog "No email is selected!"
return
end if
set theRecpt to extract name from sender of replyToMessage as text
set replyMessageSubj to subject of replyToMessage
set replyMessage to reply to replyToMessage without opening window
--need variable theName to get name or email to parse here
if has html of replyMessage then
log "HTML!"
set the content of replyMessage to ("<p>Hi " & theName & ",<br><br>This is my email body
else
log ("PLAIN TEXT!")
set the plain text content of replyMessage to "Hi " & theName & "
This is my email body" & return & (the plain text content of replyMessage)
end if
open replyMessage -- may not need to do this, you could just send it
end tell
end run
Any help would be appreciated.
Update: I have tried this:
set sender's address of newMessage to "first.last#company.com"
I get the following error:
Microsoft Outlook got an error: Can’t make address of sender of outgoing message id 292223 into type specifier.
Try:
tell application "Microsoft Outlook"
set replyToMessage to selection
if replyToMessage = missing value then
-- no email selected, don't continue
display dialog "No email is selected!"
return
end if
set theName to name of (get replyToMessage's sender)
set replyMessageSubj to replyToMessage's subject
set replyMessage to reply to replyToMessage without opening window
if has html of replyMessage then
log "HTML!"
set the content of replyMessage to ("<p>Hi " & theName & ",<br><br>This is my email body ")
else
log ("PLAIN TEXT!")
set the plain text content of replyMessage to "Hi " & theName & "
This is my email body" & return & (the plain text content of replyMessage)
end if
open replyMessage
end tell
Related
this code almost works. :) Basically I am trying to zip a file and then attach that email to a new mail message.
The process starts in automator and then the script runs. Everything works except the actual attaching of the file.
My knowledge of AppleScript is pretty limited but trying to wrap my head around this. I combined to different code snippets to get this far.
on run {input, parameters}
set display_text to "Please enter your password:"
repeat
considering case
set init_pass to text returned of (display dialog display_text default answer "" with hidden answer)
set final_pass to text returned of (display dialog "Please verify your password below." buttons {"OK"} default button 1 default answer "" with hidden answer)
if (final_pass = init_pass) then
exit repeat
else
set display_text to "Mismatching passwords, please try again"
end if
end considering
end repeat
tell application "Finder"
set theItems to selection
set theItem to (item 1 of input) as alias
set itemPath to quoted form of POSIX path of theItem
set fileName to name of theItem
set theFolder to POSIX path of (container of theItem as alias)
set zipFile to quoted form of (fileName & ".zip")
do shell script "cd '" & theFolder & "'; zip -x .DS_Store -r0 -P '" & final_pass & "' " & zipFile & " ./'" & fileName & "'"
end tell
tell application "Finder"
#I believe this is where the problem is, I am trying to use the variables from above in order to attach the file in mail.
set folderPath to theFolder
set theFile to zipFile
set fileName to zipFile
end tell
set theSubject to fileName
set theBody to "Hello sir. Here is my " & fileName
set theAddress to "Some Email"
set theAttachment to theFile
set theSender to "Some Sender"
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return, visible:true}
tell theNewMessage
set visibile to true
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
try
make new attachment with properties {file name:theAttachment} at after the last word of the last paragraph
set message_attachment to 0
on error errmess -- oops
log errmess -- log the error
set message_attachment to 1
end try
log "message_attachment = " & message_attachment
#send
end tell
end tell
return input
end run
I've fixed up most of the things that are off with your code. The following works in an automator Run AppleScript action if you pass in a list containing an alias to a file:
on run {input, parameters}
set display_text to "Please enter your password:"
repeat
considering case
set init_pass to text returned of (display dialog display_text default answer "" with hidden answer)
set final_pass to text returned of (display dialog "Please verify your password below." buttons {"OK"} default button 1 default answer "" with hidden answer)
if (final_pass = init_pass) then
exit repeat
else
set display_text to "Mismatching passwords, please try again"
end if
end considering
end repeat
tell application "System Events"
set selected_file to item 1 of input
set selected_file_name to name of selected_file
set containing_folder_path to POSIX path of (container of selected_file) & "/"
set zip_file_path to containing_folder_path & selected_file_name & ".zip"
do shell script "cd " & quoted form of containing_folder_path & "; zip -x .DS_Store -r0 -P " & quoted form of final_pass & " " & quoted form of zip_file_path & " " & quoted form of selected_file_name
set zip_file_alias to file zip_file_path as alias
end tell
set theSubject to selected_file_name
set theBody to "Hello sir. Here is my " & selected_file_name
set theAddress to "Some Email"
set theSender to "Some Sender"
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return, visible:true}
tell theNewMessage
set visibile to true
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
try
make new attachment with properties {file name:zip_file_alias} at end of attachments
on error errmess -- oops
log errmess -- log the error
end try
log "message attachment count = " & (count of attachments)
#send
end tell
end tell
return input
end run
Highlights:
I switched from using the Finder to using System Events. Avoid using the Finder unless you absolutely need to (it's a very busy app)
I set the name property of the attachment to an alias to the compressed file the script creates
I cleaned up this and that to make things clearer.
Here is what I ultimately came up with, which worked but the file handling for the attachment still needed work.
on run {input, parameters}
tell application "Finder"
set theItem to (item 1 of input) as alias
set theItemCopy to theItem
set itemPath to quoted form of POSIX path of theItem
set fileName to name of theItem
set theFolder to POSIX path of (container of theItem as alias)
set zipFile to quoted form of (fileName & ".zip")
set setPass to "Password" #test password
do shell script "cd '" & theFolder & "'; zip -x .DS_Store -r0 -P '" & setPass & "' " & zipFile & " ./'" & fileName & "'"
end tell
tell application "Mail"
set fileLocation to (fileName & ".zip")
set theSubject to "Subject" -- the subject
set theContent to "Attached are the documents from the last session." -- the content
set theAddress to "email#email.com" -- the receiver
set theAttachmentFile to "Macintosh HD:Users:dave:desktop:" & fileLocation -- the attachment path
set msg to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
delay 1
tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
tell msg to make new attachment with properties {file name:theAttachmentFile as alias}
end tell
return input
end run
I´m in the need to export a huge conversation from osx mail to a csv file. My applescript should work on selected mails. This is what I have:
tell application "Mail"
set selectedMessages to selection
if (count of selectedMessages) is equal to 0 then
display alert "Please select some message first"
end if
set mailInformation to ""
repeat with tMsg in selectedMessages
set mailInformation to mailInformation & "'" & {date received of tMsg} & "';'" & {sender of tMsg} & "';'" & {address of first recipient of tMsg} & "';'" & {subject of tMsg} & "'" & (ASCII character 10) as string
end repeat
end tell
tell application "TextEdit"
set theDocument to make new document
set text of theDocument to mailInformation
end tell
Question: how can I get the recipient of the current mail? It seemas to be a list.
This is not working:
{address of first recipient of tMsg}
Thanks!
address of first recipient of tMsg is supposed to work.
But why do you first create a list and then flatten it again? This does the same:
set mailInformation to mailInformation & "'" & date received of tMsg & "';'" & sender of tMsg & "';'" & address of first recipient of tMsg & "';'" & subject of tMsg & "'" & linefeed
In apple mail (Mail.app), I defined a rule that calls an applescript when receiving an email. The script should send the subject of the mail as an SMS message via Skype (it should also send the name of the sender). I've got already a script working that sends some hardcoded text as SMS, but I don't know how to pass the subject and senders name from mail into that SMS. Here's my script:
# Code adapted from:
# http://photolifetoys.blogspot.de/2011/12/applescript-control-over-skype-call.html
# VARIABLES
set callToAnumber to "+01234567890"
set SMSmessageBody to " has sent a mail."
set SenderOfMail to "TheSenderOfTheEmail"
set MailSubject to "TheSubjectOfTheMail"
# BODY
set smstext to "SenderOfMail" & SMSmessageBody as Unicode text
tell application "Skype"
set message to send command "CREATE SMS OUTGOING " & callToAnumber script name "SMS"
set smsid to item 2 of every word of message
send command "SET SMS " & smsid & " BODY " & smstext script name "SMS"
set result to send command "ALTER SMS " & smsid & " SEND" script name "SMS"
#display dialog "SMS send! Text: " & smstext
end tell
Now I've got the answer. Here's the code:
using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
tell application "Mail"
set the message_count to the count of these_messages
repeat with i from 1 to the message_count
set this_message to item i of these_messages
-- GET THE SENDER OF THIS MESSAGE
set this_sender to the sender of this_message
-- GET SUBJECT OF MESSAGE
try
set this_subject to (subject of this_message) as Unicode text
if this_subject is "" then error
on error
set this_subject to "NO SUBJECT"
end try
-- GET CONTENT OF MESSAGE
try
set this_content to (every character of content of this_message) as Unicode text
if this_content is in {"", "?"} then error
on error error_message
set this_content to "NO CONTENT"
end try
end repeat
end tell
set callToAnumber to "+0123456789"
# BODY
set smstext to this_subject as Unicode text
tell application "Skype"
set message to send command "CREATE SMS OUTGOING " & callToAnumber script name "SMS"
set smsid to item 2 of every word of message
send command "SET SMS " & smsid & " BODY " & smstext script name "SMS"
set result to send command "ALTER SMS " & smsid & " SEND" script name "SMS"
#display dialog "SMS send! Text: " & smstext
end tell
end perform mail action with messages
end using terms from
I'm trying to retrieve the body of any e-mail that triggers my AppleScript. I have a test message saved, and when I click "Apply Rules", I get this error:
"Can't make <> of <> id 9574 of <> "INBOX" of <> "Gmail" into type <>."
EDIT: Here's the relevant portion of the code:
using terms from application "Mail"
on perform mail action with messages messageList for rule aRule
tell application "Mail"
repeat with thisMessage in messageList
try
say content of thisMessage
on error errMsg
display alert errMsg
end try
end repeat
end tell
end perform mail action with messages
end using terms from
Try:
say (content of thisMessage as text)
Question: I would like to run an applescript against a list of selected messages in Apple OS X Mail.
Right now, the script I wrote will work on a single selection only, so I am guessing the issue is how to loop it for all items selected. Any help would be appreciated.
Here is the script:
tell application "Mail"
set theSelection to selection
set theSelectedMessage to item 1 of theSelection
set theSelectedMessageSender to sender of theSelectedMessage
set theSelectedMessageRecipient to address of to recipients of theSelectedMessage
set theSelectedMessageSenderName to extract name from sender of theSelectedMessage
set theSelectedMessageSenderAddress to extract address from sender of theSelectedMessage
set theSelectedMessageSubject to subject of theSelectedMessage
set theSelectedMessageContent to content of theSelectedMessage
set MessageText to ¬
"This email (" & theSelectedMessageRecipient & ") does NOT ¬
care to receive emails regarding this matter." & return & return & ¬
"This email was originally delivered to: " & ¬
theSelectedMessageRecipient & return & return & ¬
"Remove this email from your list: " & ¬
theSelectedMessageRecipient & ¬
return & return & ¬
"---------- ORIGINAL MESSAGE ----------------"
set theMessage to make new outgoing message with properties {visible:true, subject:"REMOVE: RE:" & theSelectedMessageSubject, content:MessageText & theSelectedMessageContent, reply to:theSelectedMessageRecipient}
tell theMessage
make new to recipient at end of to recipients with properties {name:theSelectedMessageSenderName, address:theSelectedMessageSenderAddress}
end tell
end tell
set theSelectedMessage to item 1 of theSelection
Replace this with:
repeat with theSelectedMessage in theSelection
Just before the last line, add:
end repeat