Hi, I’m using AppleScript on an iChat account so that when I send a message to it, it processes it and can respond and carry out tasks. I am trying to get it to send an email message for me.
Something like…
Me: Send email message
It: Details?
Me: To: my@address.com Subject: How are you? Body: Hello there!
It opens mail, sends message: Message sent.
Maybe this might help…
on send_email(theAddress, theSubject, thebody)
tell application "Mail"
set mymessage to make new outgoing message with properties {visible:true, address:theAddress, subject:theSubject, content:thebody}
tell mymessage to make new bcc recipient at end of to recipients with properties {address:theAddress}
send mymessage
end tell
end send_email
Any help would be appreciated!!
I know what you mean. I know how to send a email via script. Maybe I can do something with your “o: my@address.com Subject: How are you? Body: Hello there!” things.
I got this. Save it as an application and add this to it’s bundle contents. It might not work. Just post your problems here:
property login : {name:"", password:"", smtp:""} --email, password, then the SMTP server address
tell application "Mail" to set xs to content of messages of inbox whose subject is "SENDMESSAGE" --do this the iChat way. I don't know that.
repeat with x in xs
processdata(x)
sendemail(result)
end repeat
on processdata(x)
set text item delimiters to "|TO|: "
set x1 to text item 2 of x
set text item delimiters to " |SUBJECT|: "
set x1 to text item 1 of x1
set x2 to text item 2 of x
set text item delimiters to " |MESSAGE|: "
set x2 to text item 1 of x2
set x3 to text item 2 of x
return {x1, x2, x3}
end processdata
on sendemail(o)
set z to " -u " & item 2 of o
if item 2 of o is "" then set z to ""
try
do shell script quoted form of POSIX path of (path to resource "sendEmail") & " -f \"" & (system info)'s long user name & "<" & login's name & ">" & "\" -t " & (item 1 of o) & z & " -m " & item 3 of o & " -s " & login's smtp & " -o username=" & login's name & " -o password=" & (login's password)
do shell script quoted form of POSIX path of (path to resource "sendEmail") & " -f \"" & (system info)'s long user name & "<" & login's name & ">" & "\" -t " & login's name & " -u Sent." & " -m " & "Message sent successfully." & " -s " & login's smtp & " -o username=" & login's name & " -o password=" & (login's password)
on error
do shell script quoted form of POSIX path of (path to resource "sendEmail") & " -f \"" & (system info)'s long user name & "<" & login's name & ">" & "\" -t " & login's name & " -u Fail." & " -m " & "Message " & quoted form of item 2 of o & " fail to send successfully." & " -s " & login's smtp & " -o username=" & login's name & " -o password=" & (login's password)
end try
end sendemail
Hi, thanks very much for that Dylan but I can’t access that zip file that’s hosted on MacTweaks.info
I have been trying to solve some of this for myself, whilst my internet was down for a while…
I have an applescript starting like this:
using terms from application "iChat"
on message received theMessage from theBuddy for theChat
and i’ve set it in iChat preferences so it runs when a message is received from my normal AIM account.
This is what I’ve got so far (when it sends “Details?”, I send the details of the email, for it to process and send). I’m not sure whether this might help by the way…
set One to theMessage
--This is the format of the details that I'll send back...
To: email@gmail.com Subject: Testing AppleScript Body: Hello, this is a test email!
on replaceText(find, replace, someText)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set someText to text items of someText
set text item delimiters of AppleScript to replace
set someText to "" & someText
set text item delimiters of AppleScript to prevTIDs
return someText
end replaceText
set Two to (replaceText("To:", "", One))
--return Two
--email@gmail.com Subject: Testing AppleScript Body: Hello, this is a test email!
set Three to (replaceText("Subject:", "", Two))
--email@gmail.com Testing AppleScript Body: Hello, this is a test email!
--return Three
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to " "
--set theAddress to text item 1 of Three
--return text items of Three {"", "email@gmail.com", "", "Testing", "AppleScript", "Body:", "Hello,", "this", "is", "a", "test", "email!"}
--NOT WORKING
set text item delimiters of AppleScript to prevTIDs
--return theAddress
--return AppleScript's text item delimiters returns: {""}
I finally finished my own script! Any ideas on how to improve it?
Thanks to Chad Barraford for the on send_email and on replaceText parts!
(This is a little chunk of my iChat Script…)
on send_email(theAddress, theSubject, theBody)
tell application "Mail"
set mymessage to make new outgoing message with properties {visible:true, subject:theSubject, content:theBody}
tell mymessage to make new bcc recipient at end of to recipients with properties {address:theAddress}
send mymessage
end tell
end send_email
on replaceText(find, replace, someText)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set someText to text items of someText
set text item delimiters of AppleScript to replace
set someText to "" & someText
set text item delimiters of AppleScript to prevTIDs
return someText
end replaceText
using terms from application "iChat"
on message received theMessage from theBuddy for theChat
if theMessage contains "send" and theMessage contains "email" then
delay 1
send "Details?" to theBuddy
end if
if theMessage contains "To:" or theMessage contains "Subject:" or theMessage contains "Body:" or theMessage contains "@" then
set One to theMessage
set Two to (replaceText("To:", "", One))
set Three to (replaceText("Subject:", "", Two))
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to " "
set TA to text item 2 of Three
set text item delimiters of AppleScript to "Body:"
set |number| to (count text items of Three)
set TB to text item 2 of Three
set theSubject1 to (replaceText(space & TA & space, "", Three))
set theSubject2 to (replaceText("Body:" & TB, "", theSubject1))
set TS to theSubject2
set text item delimiters of AppleScript to prevTIDs
send_email(TA, TS, TB)
end if
end message received
end using terms from