Friday, December 15, 2017

#1 2015-05-29 10:13:09 pm

Santa
Member
From:: Land of Oz
Registered: 2006-07-27
Posts: 486

I want to add attachment in outgoing Mail message, at beginning.

G'day folks

This is a last ditch attempt at finding answers to this.

Shane Stanley has helped me so far, and I'm grateful for his help, but he doesn't know the answer to these questions (if there are any).

He's shown me how to make an outgoing message using ASObjC, but it appears that adding attachments to the message always adds them at the end, and I need to add them at the start, not at the beginning.

As well, I can't find out how to actually send the message. All Finder and System Events to an outgoing message are ignored, do how do I send it?

Any advice appreciated, please?

Regards

Santa

Applescript:



on eMailit(the_subject, the_content, theCCRecipientsStore, textcolor)
   
tell application "Finder"
   try
       set pathToMe to path to current application as text
       set logoPath to pathToMe & "Contents:Resources:Report Logo.png" as text
       set PosixLogoPath to POSIX path of logoPath
   on error
       set logoPath to ""
   end try
   set p to 2
   if ((count of logoPath) as text) < 4 or not (exists file logoPath) then
       try
           set pathToMe to (path to applications folder) & "Mail Manager:Mail Manager.app:" as text
           set logoPath to pathToMe & "Contents:Resources:Report Logo.png" as text
           set PosixLogoPath to POSIX path of logoPath
       end try
   end if
end tell

set p to 2.1
set anNSURL to current application's |NSURL|'s fileURLWithPath:PosixLogoPath
-- make file wrapper from URL
set p to 2.2
set anNSFileWrapper to current application's NSFileWrapper's alloc()'s initWithURL:anNSURL options:0 |error|:(missing value)
-- make attachment from file wrapper
set p to 2.3
set anNSTextAttachment to current application's NSTextAttachment's alloc()'s initWithFileWrapper:anNSFileWrapper
-- make attributed string from attachment
set p to 2.4
set theAttachment to current application's NSAttributedString's attributedStringWithAttachment:anNSTextAttachment

<CODE>

set anNSString to current application's NSString's stringWithString:the_content
set p to 22
set anNSMutableAttributedString to current application's NSMutableAttributedString's alloc()'s initWithString:anNSString attributes:(missing value)

<CODE>

set mailShare to current application's NSSharingService's sharingServiceNamed:(current application's NSSharingServiceNameComposeEmail)

mailShare's setRecipients:{mailRecipients}
mailShare's setSubject:the_subject

# Adds attachment to end, not beginning
mailShare's performWithItems:{theAttachment, anNSMutableAttributedString}

Model: Late 2014 retina i7, Yosemite
AppleScript: 2.4
Browser: Safari 600.2.5
Operating System: Other


Just an enthusiastic old fart of an Apple user since the IIe days

Offline

 

#2 2015-06-18 12:08:56 am

leonsimard
Member
From:: Montreal, Canada
Registered: 2009-09-27
Posts: 526

Re: I want to add attachment in outgoing Mail message, at beginning.

Have you tried to integrate the attachment inside the NSMutableAttributedString, at the beginning? No idea what the result would be though. Would only work if it's an image I reckon...

Secondly, why use NSSharingService ? Why not just a plain old applesript? Just curious...

And maybe you could try to create an HTML message? I've tried to in the past, but couldn't make it work, even though the command in AS is there.

Browser: Safari 534.51.22
Operating System: Mac OS X (10.8)

Offline

 

#3 2015-06-18 04:47:59 am

Santa
Member
From:: Land of Oz
Registered: 2006-07-27
Posts: 486

Re: I want to add attachment in outgoing Mail message, at beginning.

G'day Leon.

I, and Shane Stanley, have tried to put the Attachment at the start of the attributed text, but Mail moves it to the end when the attributed text is pasted in. Also, there's actually no way of sending the Mail message that's created with attributed text.

I want to use attributed text because the normal method of creating a Mail messages takes over 2 minutes to alter the text (colors of certain items, text size likewise), of one of my apps Annual reports, whereas attributed text does it in 1 second.

I've lodged a bug report.

Regards

Santa


Just an enthusiastic old fart of an Apple user since the IIe days

Offline

 

#4 2015-06-18 07:58:53 am

leonsimard
Member
From:: Montreal, Canada
Registered: 2009-09-27
Posts: 526

Re: I want to add attachment in outgoing Mail message, at beginning.

I see. Did you check the pref in Mail (if you are using Mail) ? In the Edit menu > Attachment > Always put attachments to the end of message or something like that... if it's checked, it may be causing the problem.

Offline

 

#5 2015-06-18 05:29:49 pm

Santa
Member
From:: Land of Oz
Registered: 2006-07-27
Posts: 486

Re: I want to add attachment in outgoing Mail message, at beginning.

G'day Leon

It's not checked, but seems to default to it anyway, regardless.

Also, the problem of not being able to send the complied message when using NSSharingService is also stopping me. The message won't even respond to GUI commands.

Regards

Santa


Just an enthusiastic old fart of an Apple user since the IIe days

Offline

 

#6 2015-06-18 05:47:28 pm

leonsimard
Member
From:: Montreal, Canada
Registered: 2009-09-27
Posts: 526

Re: I want to add attachment in outgoing Mail message, at beginning.

Yeah, makes sense that NSSharingService would not be ideal, it's waiting for the user's interaction.

I've had similar problems in the past with creating emails, dunno why, but always been a pain in the ass for something that is so simple and also used a million times a day.

Did you check up the SBSendEmail sample project in the docs? It uses Scripting bridge, and although this is a framework that is difficult to use, this example might give you a head start on something. It's basically what you could do with applescript but with the added bonus of having access to all other frameworks and classes.

Last edited by leonsimard (2015-06-18 06:07:37 pm)

Offline

 

#7 2015-06-18 06:05:36 pm

leonsimard
Member
From:: Montreal, Canada
Registered: 2009-09-27
Posts: 526

Re: I want to add attachment in outgoing Mail message, at beginning.

Or even this SDK :

http://cocoadocs.org/docsets/mailgun/1.0.3/

Or this:

http://www.mulle-kybernetik.com/software/EDFrameworks/

Or even these :

http://stackoverflow.com/questions/1136 … from-cocoa

http://stackoverflow.com/questions/5461 … from-cocoa
This last one, scroll down to the bottom, it may be interesting since you are using NSSharedService.

Offline

 

#8 2016-01-14 12:36:48 pm

wouter
Member
Registered: 2015-05-29
Posts: 6

Re: I want to add attachment in outgoing Mail message, at beginning.

using NSSharingService,
I have 2 additional questions:
1. Is there a way to define the sender (I have mail configured with multiple accounts and like to programmatically set a certain account)?
2. Can the mail be send out automatically, not just created ?

Offline

 

#9 2016-01-14 06:21:11 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: I want to add attachment in outgoing Mail message, at beginning.

wouter wrote:

using NSSharingService,
I have 2 additional questions:
1. Is there a way to define the sender (I have mail configured with multiple accounts and like to programmatically set a certain account)?
2. Can the mail be send out automatically, not just created ?


Alas, no to both.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#10 2016-01-15 05:03:42 am

wouter
Member
Registered: 2015-05-29
Posts: 6

Re: I want to add attachment in outgoing Mail message, at beginning.

Thank you for the quick answer Shane.
Unfortunately a bad answer.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)