OO Calc Macro to emailing with attmt on Apple Mac OSX10.15

Creating a macro - Writing a Script - Using the API

OO Calc Macro to emailing with attmt on Apple Mac OSX10.15

Postby alf50 » Wed Apr 28, 2021 4:29 am

OpenOffice Calc Macro to automate emailing with attachment on an Apple Mac OSX 10.15.

I have been using OpenOffice Calc on my Apple Macintosh computer for 12 years now. I do not use Microsoft Excel any more for basic coding.
I have enjoyed using the Built in Basic Command Language of OpenOffice to do most of the coding that I do. I do some Python coding, but not much.
There are many UnoServices that work under Ubuntu, LibreOffice, Window7 or 10, to send Emails with attachments such as:

eMailer = createUnoService ("com.sun.star.system.SimpleCommandMail")
eMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )
eMailer = createUnoService("com.sun.star.system.SystemMailProvider")

but

none of them work if you are using an Apple Mac. My question is, WHY NOT?

The only one that I have found that works without an attachment is launcher.executive

launcher = CreateUnoService("com.sun.star.system.SystemShellExecute")

The code looks something like this:
Code: Select all   Expand viewCollapse view
Sub SimpleMailTo(eAddress as string, eSubject as string, eBody as string, CCeAddr as string, BCCeAddr as string)

Dim aHTMLanchor as string
Dim launcher as object
Dim eMessage as Object

launcher = CreateUnoService("com.sun.star.system.SystemShellExecute")

aHTMLanchor = "mailto:" & eAddress & "?cc=" & CCeAddr & "&&bcc=" & BCCeAddr & "&&subject=" _
& eSubject & "&&body=" & eBody

launcher.execute(aHTMLanchor, "", 0)

End Sub

Even this will not totally automate the send without an additional AppleScript to activate the emailing:
Code: Select all   Expand viewCollapse view
on run
   delay 2
   
   --   tell application id "com.apple.Mail"
   --      set sendButton to localized string "ToolbarSend"
   --   end tell
   
   tell application "Mail"
      set sendButton to localized string "ToolbarSend"
   end tell
   
   tell application "System Events" to tell process "Mail"
      set frontmost to true
      tell window 1
         tell toolbar 1
            click (first button whose description = sendButton)
            delay 10
         end tell
      end tell
   end tell
end run

I thought things were finally fixed with the SystemMailProvider UnoService.

The following code actually will attached a file, jump to the Apple Mail.app and display the message with the attachment. But all the other parts of the mail message like Mailto:, CC:, BC:, Subject: and Body: do not get passed across. No one seems to have finished the interface routines for the Mac Operating system.

Using: eMailer = createUnoService("com.sun.star.system.SystemMailProvider"), here is the code that attaches the file to the email but does nothing else.
Code: Select all   Expand viewCollapse view
Sub openEmailClientTxt2(EmailAddr as string, SubjectTxt as string, BodyTxt as string, OpenWin as integer, AttchURL as string)

On Error GoTo ErrorHandle:

Dim eMailer as Object, eMailClient as Object, eMailMessage as Object

eMailer = createUnoService( "com.sun.star.system.SystemMailProvider" )
eMailClient = eMailer.queryMailClient 
eMailMessage = eMailClient.createMailMessage()
eMailMessage.Recipient = EmailAddr
eMailMessage.Subject = SubjectTxt
eMailMessage.Body = BodyTxt
eMailMessage.Attachement = array(AttchURL)
eMailClient.sendMailMessage(eMailMessage,OpenWin)

'     UI=OpenWin  ' 0 = open email msg to edit, 1=send w/o opening.
'              Some email program will require a confirmation window to open
'     MailClient.sendSimpleMailMessage(MailMessage, UI)
     
     Exit Sub
     
     ErrorHandle:
     msgbox "email could not be sent"
     
End Sub


I solve this problem in 2008 by passing all the parameters in a comma separated file to an AppleScript that builds the email and sends it. But I thought after 12 years that someone would actually complete the code for one or all of the UnoServices that have been around and completed for the other platforms for the past 12 years.

So again, my question is WHY NOT???
OpenOffice 4.1.10 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2021update) & MS Wnds10
User avatar
alf50
 
Posts: 121
Joined: Sun Jun 13, 2010 2:55 pm

Re: OO Calc Macro to emailing with attmt on Apple Mac OSX10.

Postby Villeroy » Wed Apr 28, 2021 11:29 am

OpenOffice has died. This forum is the most active part of the project, with 10% of the activity compared to 2010, though.
In 2011 the project was taken over by Oracle Corp. and then passed over to the Apache foundation. At the same time the code was forked to a new project https://libreoffice.org and this is where the music plays now. Please have a look at https://www.libreoffice.org/discover/li ... penoffice/
Hardly anybody writes any code for Apache OpenOffice. It is just enough for not being kicked off the Apache foundation.

I tested the code with AOO 4.1.9 on LInux
Code: Select all   Expand viewCollapse view
Sub Main
eMailer0 = createUnoService ("com.sun.star.system.SimpleCommandMail")
eMailer1 = createUnoService( "com.sun.star.system.SimpleSystemMail" )
eMailer2 = createUnoService("com.sun.star.system.SystemMailProvider")
End Sub

eMailer2 is a valid object, the other two are Null.

With LibreOffice 7.1 eMailer0 is a valid object, the other two are Null.

I do not use any macros for mail attachments since menu:File>Send>Send Email ... works fine for me and I can not find anything to the contrary in our Mac OS FAQ
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 30110
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: Google [Bot] and 15 guests