I am new to applescript and I am running into an issue.
I have setup a rule in mail to check incoming mails and trigger a script. What do I need to change in the script below ? The problem is in the script not the rules.
The script will not go beyond what I have below until I select it myself.
What would be the right code so I don't have to actually select the email.
Thanks.
tell application "Mail" -----check mail for incoming emails
set theMessage to message 1 of mailbox "INBOX" of account "GMAIL"
set thebody to content of theMessage
set theSelection to selection
set theMessage to item 1 of theSelection
content of theMessage
end tell
The basic syntax for a mail rule is
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with aMessage in theMessages
set thebody to content of aMessage
-- do other things with aMessage
end repeat
end perform mail action with messages
end using terms from
The script must be saved in ~/Library/Application Scripts/com.apple.mail/, then you are able to select it in the dialog window to create and edit a rule.
If I understand what you are asking, you just need to add the following lines to vadian's answer (replacing "-- do other things with aMessage")
set myword1 to the first word of body
set myword2 to the second word of body
There are lots of good resources for learning AppleScript at MacOSX Automation
Thanks for your help.
I guess that was what I needed at the time.
I found a workaround by just having Automator mark the message as read.
That did the trick to trigger my script automatically as soon as the message comes in.
Related
I have set my Sendgrid single sender and validate it ( status = verified).
I use SMTP, create my key that i paste in my code (.env file of my app):
MAILER_DSN=sendgrid+smtp://#default
Then i try to test integration in Sendgrid by clicking on button and refresh my localhost/ page (of course the controller's route is "/" and it contains the code using mailer to send a mail as explain in mailer documentation).
On my vue i don't have error code but mail stay in queue status...
Here the screenshot taken of the profiler:
Can someone tell me why my mail stay queued?
Of course the From email address is mine ( the verified one) and the To is anotherone of mine.
Maybe i have to configure something in my outlook mail (the From one) ?
Sendgrid never match the verification, it stay in checking status until message :
Hmm, we haven't seen your email yet.
Please check your code, run it again, then click "Retry".
Thanks for reply,
Regards,
In your question you said that your MAILER_DSN environment variable is set to:
MAILER_DSN=sendgrid+smtp://#default
That is missing your API Key though. You need to create an API key in the SendGrid dashboard and then add the API key to the MAILER_DSN variable, between the // and the #default like this:
MAILER_DSN=sendgrid+smtp://API_KEY#default
One other thing, ensure that you have installed the SendGrid transport with this command:
composer require symfony/sendgrid-mailer
Yes, thanks you a lot for reply.
Of course all was set as you notify me.
I now have fix my issue, in fact the problem for me with the mail that remains in queued is that the messenger was installed so in asynchronous by default.
I had to add the option message_bus: false in my config/packages/mailer.yaml file not to have the asynchronous option used.
Hopefully this is useful for some people.
add the option message_bus: false in my config/packages/mailer.yaml:
framework:
mailer:
dsn: '%env(MAILER_DSN)%'
message_bus: false
I use AppleScript and can send messages without any problem, but the "Sent" box does not get a copy of what I sent. However, if I use Mail Application to send messages, the "Sent" box gets a copy of what I sent. So I guess my AppleScript may miss a command or so to tell Mail to keep a copy of the sent messages. What's the command that I missed? Thanks.
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 false
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
make new attachment with properties {file name:theAttachment} at after the last paragraph
send
delay 5
end tell
end tell
I don’t think you’re missing any command. I copied your script to Script Editor on my iMac, set values for theSubject, theBody, theAddress, theSender, and theAttachment, and ran it. It (a) successfully sent the message, and (b) I was able to view the message it sent in my Sent mailbox.
I tried this both with a known sender and with a random example.com sender. In both cases, it was saved in the default Sent box.
So the issue most likely lies elsewhere. Make sure that the value you’re currently using for theSender maps to an account in Mail that saves sent messages. (If it’s an IMAP account, it may be saving sent messages on the server, and server behavior may be affecting what you see.)
If that doesn’t work, set up some test values for all of the variables in the script except theAddress (using example.com for theSender), and include those (except theAddress) in your question. (If you can use example.com for theAddress, too, do that, but some servers will simply refuse the message immediately, which makes it worthless for testing this particular case.)
Note that you have an error that does not change this behavior; you have “visible” misspelled as “visibile”. However, I tried it both ways and in both cases the outgoing message does get stored in the appropriate Sent box.
Try adding this after you send the message...
set accountReference to first account whose name = "my account name"
synchronize with accountReference
I have an AppleScript I want to apply to individual emails (to archive them as PDFs with a particular file name), ut can't work out how to apply it to specific emails.
I can't set up a mail rule to run the script as it is just my judgment as to whether I want to archive one out of Mail or not. Have tried setting it up as a Service, but there is no Services menu on right clicking an email in Mail.
Any suggestions?!
Rich
How are you planning on specifying which individual emails? If by selecting them manually, you can “get selection”. Here’s a simple script that will get the subject and message Id of each selected message.
tell application "Mail"
set mySelection to get selection
set eMails to {}
repeat with selectedMessage in mySelection
set messageId to selectedMessage's message id as string
set eMail to selectedMessage's subject & ": " & messageId
tell me to set end of eMails to eMail
end repeat
set AppleScript's text item delimiters to "\n\n"
set the clipboard to (eMails as string)
end tell
Save it in ~/Library/Scripts/Applications/Mail/ and it will show up in your Scripts menu. You may have to go to AppleScript Editor’s settings to “Show Script menu in menu bar” to make the Scripts menu show up.
(Note: when you compile this script, the \n\n will turn into new lines.)
I have a data stream that will be sent as daily emails containing temperature and wind speed from a measurement site. I would like to to automatically filter out these emails from the other emails I receive, then save the email body content to its own text file. Each text file must have a distinct file name; for example it could include the time that the email was sent or received. All files must all end up in a chosen directory. And ideally the process would be robust enough that it could run unattended for weeks. Our email system is Outlook but I could choose to send the email to my gmail account, for example. What is the big picture of how to do this?
Bigger picture: create a VBA script that runs on the Items_ItemAdd event, which fires whenever an email arrives.
Specifics: Use the solution on this page, but in the Items_ItemAdd routine change the olSaveAsMsg to olSaveAsTxt to get the text format you want.
Note that the file name format in the example should match what you need, but you'll need to add criteria to the Items_ItemAdd routine to check that the message is one that you want to save. For example, you could read the Item.Subject property.
it means you are working with exchange, i suggest to use imap protocol to read the mails, and you will be able to save the body.
I need to use applescript to process the body of an email during incoming.
How can I get the body of an email when using Outlook 2011?
I am totally new to Applescript.
Any tutorial for using Applescript with Outlook 2011 or starter code for this question would be greatly helpful.
set theText to string
tell application "Microsoft Outlook"
set messages to selection
repeat with this_message in messages
set theText to content of this_message
end repeat
end tell
Now theText has the contents of the message.