AppleScript email with rich content on OSX 10.11 (El Capitan) - email

I am trying to send styled text email through AppleScript via default mail client. It seems new version of OSX is not able to recognise the HTML content set inside. Is there any workaround for 10.11 (El Capitan)?
Solution is working pretty much fine with 10.10 (Yosemite).
tell application "Mail"
set theMessage to make new outgoing message with properties {subject:textSubject, visible:false}
tell theMessage
set html content to textBody
repeat with i from 1 to count toNameList
make new to recipient at theMessage with properties {name:item i of toNameList, address:item i of toAddressList}
end repeat
send
end tell
end tell

Related

Using Applescript to get the body text ( content ) of a loaded template

I have a piece of applescript that creates a new mail message and then loads a template into that message.
So far so good.
I want to get the content ( body text ) after the template being loaded.
How can I get the body content after loading the template?
Reason is, I need to replace some text ("/date/") with a date.
The body could be HTML or just plain text.
I know how to get the content when an existing mail is selected, so it is questioned really only about this case.
BTW, a secondary question. Now I use button click to load the template, but is there a better way, for example load the template directly by name?
Thank you very much
edit addition
I'am a step further. It is solved for this problem.
First I did make a new email using
tell application mail
-- make email and visible
-- then for using the keystrokes and gui to get the template
tell application system events
tell process mail
-- tell window to get template - works fine
-- SEE NOTE 1
set _content to content of myMessage -- it doesn't work, message ID is there
set the _content to (get the value of the last scroll area) -- it doesn't work
-- IN HERE I CANT'T get the content of the message, should be with the ui?
-- if someone knows, please
end tell
end tell
-- now I have to Activate the mail app. I didn't know
activate --
set _content to content of myMessage -- works
set the clipboard to _content as string -- works almost
-- SEE NOTE2
Note 1
In here I can't get the content of the message, should be with the ui?
if someone knows, please
Note 2
If I paste the clipboard, the text has a different font.
How can I get the right type of font in my clipboard?
Still searching for a better way for getting the template.
I answered a similar question here
https://stackoverflow.com/a/23069553/348694
The trick there was to use a preformatted rtf file, copy it to the clipboard and then paste it in the message.
This way you can easily change the content with a search/replace before you copy it into the clipboard for pasting.
HTH

Send email from clipboard without opening Thunderbird

I asked a question called Send email from clipboard without opening mail.app
Now, I can do this using
set a to "post+UPReuNmbK7pR+414760#checkvist.com"
tell application "Mail"
tell (make new outgoing message)
set subject to (the clipboard)
set content to ""
make new to recipient at end of to recipients with properties {address:a}
send
end tell
end tell
I want to do the same in windows 7, preferably using AHK and Mozilla Thunderbird, since I already have these programs installed. I cannot, however, write this due to my poor programming skills.
I found the answer on lifehacker, here http://lifehacker.com/355941/quickly-compose-new-gmail-messages-with-launchy

Forwarding all iMessages to email using AppleScript

I'm new to AppleScript but learned a bit from searching online. Basically I would like to forward iMessage messages to an e-mail address. I did this with the following script:
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:"thesubject", content:theMessage, visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties {address:"myemail#gmail.com"}
send
end tell
end tell
end message received
end using terms from
Works great and it puts the iMessage in the content of an e-mail that gets sent to me.
Now I'm trying to do this with attachments as well. I modified the code to give me 4 beeps when a file is received but nothing happens. Posted this question to Apple's website but then I thought I would have better luck here. Any help would really be appreciated I've searched google for hours and I'm kind of at a dead end.
Modified Code:
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
tell application "Mail"
set theNewMessage to make new outgoing message with properties
{subject:"thesubject", content:theMessage, visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties
{address:"myemail#gmail.com"}
send
end tell
end tell
end message received
on completed file transfer theFile
beep 4
end completed file transfer
end using terms from
So with a bit more looking I learned that Messages is very similar to iChat which I found some example code on Apple's Developer site:
https://developer.apple.com/library/mac/#samplecode/iChatAppleScriptSamples/Listings/Add_Incoming_Images_to_iPhoto_Add_incoming_image_to_iPhoto_applescript.html
So I changed my code to this:
on received file transfer invitation theFileTransfer
accept transfer of theFileTransfer
tell application "Mail"
set theNewMessage to make new outgoing message with properties
{subject:"photo", content:"themessage", visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties
{address:"myemail#gmail.com"}
send
end tell
end tell
end received file transfer invitation
I also made sure to have the script run when incoming file in the Messages preferences window, but still not getting any response. Very frustrating, I'm thinking that a picture might not be a file transfer but rather an inline text attachment of sorts.
Looking at the Messages dictionary I found:
attachment n [inh. rich text] : Represents an inline text attachment. This class is used mainly for make commands.
elements
contained by rich text, characters, paragraphs, words, attribute runs.
properties
file (file, r/o) : The path to the file for the attachment syn file name
But I have no idea how to use classes in AppleScript.
Again any help would be greatly appreciated!
I’ve been in AppleScript hell for the past few days. Apparently, when Apple changed how Messages.app deals with events (one event handler instead of a script per event), they either broke or failed to implement file transfer-related stuff.
Attachments are not accessible because you are never given a file object; rather (you’ve discovered) you get a message string and user and chat objects.
There’s good news in all of this, though (kind of). on message received is triggered for text messages and media messages. For media messages, the text string your handler gets is empty. You can hit up last file transfer to see if anything was recently received and act accordingly.
Here’s the nasty hack I’m using in the message received handler to get attachments:
set fileName to ""
if direction of last file transfer is incoming then
-- compare diff in seconds
if (current date) - (started of last file transfer) < 5 then
set f to file of the last file transfer
set fileName to POSIX path of f
end if
end if
Do note that it’s only the start of an idea. I haven’t had time to improve it since I banged it out a few days ago. You’ll get the full path to the file in fileName if the message has media.
For the Mail.app side of things, basically, I have no clue. To send images with Messages.app, I’m using set theMessage to POSIX file fileName. Probably something along those lines for setting the file for attachment.
AppleScript is like messed up English, which is why you can use first and last and 2nd and even 1th or 3nd. You can do stuff like get number of file transfers but get number of file transfer is also valid.
Partially related: checkout out properties if you ever want to inspect an object. properties plus the AppleScript Editor (as in get properties of first chat) are a lifesaver.
Good luck.

Use Automator to email a word doc

I do work over a few computers and use my email address to keep an extra save copy of my files. I'd like to have an Automator service for Microsoft Word that sends an email to myself with the current word doc as an attachment and the title as the subject. If I could have a macro in Word that did the same thing that would also be great. Thanks.
You can either run this as an AppleScript by itself or insert the AppleScript in your Automator workflow.
tell application "Microsoft Word"
try
set theTitle to name of front document
end try
send mail front document
end tell
tell application "Mail"
activate
tell its outgoing message 1
set subject to theTitle
end tell
end tell

Lotus Notes email as an attachment to another email

This is in Notes 8.5 environment.
I just wanted to know how to attach an email to another email as real attachment not a "Document Link".
I intended to attach an email, so I drag & dropped an email to another email's body but this turned out to be a "Document Link". This is an issue when I deleted the original attachment(an email in this case) and want to open the attachment again.
Tried to drag & drop the email to desktop and attach that through the "Choose file" dialog, didn't work either.
So how can I do that? I'm trying to get the attachment programmatically.
The only way I know is this:
Reassure that preferences | Basic Notes Client configuration | Drag and drop saves as eml file is checked
1) Drag your email to e.g. your desktop or to an explorer instance (will be saved as an eml file).
2) Attach this file to your opened email by either selecting it with the paperclip menu item or drag 'n drop the file into the opened email.
Open msg
Save to desktop
Open new mail
Attached *.eml file on desktop
Sad to say, this is the only way I know which sux because in Outlook, you just need to copy and paste.
Answer from Chris is not possible
because there is no save mail option
(at least in version 8.5) in LN
It is possible, File > Save As
answer from Alexey creates MS Outlook eml files, so if you don't have Outlook e-mail client doesn't help.
Answer from Chris is not possible because there is no save mail option (at least in version 8.5) in LN.
So one of the possible solutions would be to hold control, select all mails you want to attach, right click on the selected mails, from the menu select Forward and it will open the new message with all selected mails in the body of the new message.
You can slecet sent item /email and drag to desktop , it will automatic created new file on desktop. Then you can attach and send it in to new emails.
I have recently encountered the same issue and hopefully what follows will be helpful.
In Windows, the default program for opening .eml files is set to Outlook. Every user of Lotus notes should take the steps to have .eml files defaulted to open via Lotus notes.
Start menu--- Defaults programs---Lotus notes-- and check .eml--- then save.
After performing this, Lotus notes will be the default to open these attachments.
I have been trying to do this for a while also.
Here is what I do now.
Highlight the email you want to create as a file.
Click on Create. Hover over Special, then click on Link message.
This will open up a new tab for the link.
At the bottom of the message is a small yellow piece of paper icon.
Copy this icon and paste into your message like you would any other file.
It is tiny, so I put a statement like "see email attachment ---->" in front of the icon.
You might like this way. Not sure though.
Tested vith Notes versions 6.5.x and 7.0.x
From your Lotus Notes inbox
Open the message
Click View > Show > Page Source
Copy all the data into a text file and save the file with .eml extension.
Create a new message
Attach the .eml file(s) and send the new message
Hop this helps. I have no client on my current machine but will test from home on 8.5.1
Copy the mail as a document link (right click on the mail and you should get this option) and paste it in the new mail. This worked for me
Talking about IBM Notes v. 9 is pretty easy.
To choose the e-mail to be attached and drag until the new e-mail.
Click on email which you want to forward
Edit - > Copy As -> Document Link
create new mail and paste.
it will work
If you are using Lotus Notes V9.X, it is better to drag the mail to desktop as .eml and then attach it to the mail. Safest way so far.
Although probably not exactly what your looking for and you probably don't care at this point since the question was asked 5 years ago, one method is to use "forward".
Go to your inbox or wherever your messages are and select the 2+ messages you want to send than simply click forward... all messages get combined into 1.
I might be very late but encoutered this problem sometime before and saw this link.
Thanks . Please check this shall work.
Goto Create menu -> Section--> Copy email to be inserted