[Calc] Macro to Config&Send Mail directly from OOffice

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
alf50
Posts: 129
Joined: Sun Jun 13, 2010 2:55 pm

[Calc] Macro to Config&Send Mail directly from OOffice

Post by alf50 »

rem ----------------------------------------------------------------------
rem --- This macro sends an Email directly from a LibreOffice Basic shell command.
rem --- This is run under the Twister OS after installing and
rem --- configuring the Mutt command line Email app.
rem --- The Mutt app is available for both Macs, PC and Linux based Computers.
rem --- I am now using the Mutt Email App on a Raspberry Pi 4 running Twister OS.
rem --- Developed by Al Forster, AVFConsulting LLC, Aug,2021
rem ----------------------------------------------------------------------

Code: Select all

sub SEmailshell
rem ----------------------------------------------------------------------
Dim TermProcLoc, BodyTxt, Subject, EMaddress, DocPath as string
Dim mut as string, mut1 as string, mut2  as string
rem ----------------------------------------------------------------------
TermProcLoc = chr(34) & "bash -c 'exo-open --launch TerminalEmulator " 
BodyTxt= "please find file attached "
Subject= "Attachment test"
EMaddress = "Client1@gmail.com "
DocPath= "/home/pi/Desktop/Document/pdfgen-1.pdf"
rem ----------------------------------------------------------------------
mut1 = "echo " & chr(34) & BodyTxt & chr(34) & " | mutt -s " & chr(34) & Subject & chr(34) & " "
mut2 = EMaddress & "  -a " & chr(34) & DocPath & Chr(34)
mut = mut1 & mut2
'msgbox "mut= " & mut
shell "bash -c 'exo-open --launch TerminalEmulator " & mut & "'" & Chr(34)
rem ----------------------------------------------------------------------
end sub
For the past 8 years, I have been asking this Forum for a way to use an OO Calc Macro to Config, & Send Mail directly from OOffice to my clients. The standard answer has been to use a .uno developed utility like:
eMailer = createUnoService("com.sun.star.system.SimpleSystemMail")
When asking for the link to the Mail Client with the query command:
eMailClient = eMailer.querySimpleMailClient().
I have always gotten the Error Message: Error: Basic Runtime error: "Object Variable Not Set"
The problem is that this routine works when you are using Windows XP, 7 or 10. But if you are using an Apple Mac or Linux based computer, you get the error mentioned above. The Mail Client recommended is usually Thunderbird. Since I prefer using a Mac for developing code, I had to develop my own emailing routines which involved outputting Body ,Subject, EMailAddresses, DocPath (to file Attachments) to a file, then launching an AppleScript that would send out the document using the Apple Mail Client App. That was a long tedious process but I finally got it working flawlessly.
I started using the Raspberry PI 3b, a $35.00 computer about 4 years ago. I did not think it was fast enough then, but in the past year the Raspberry Pi 4b has arrived for about $45.00, fully configured with a 256gb SSD and Monitor for about $150. Anyway, configuring that with the Free, Open Source Twister OS, one can configure it to look like a Mac running Big Sur, or like a Windows 10 Computer. All you have to do is open a configuration menu and select a different "SKIN".

The bottom line is, with Twister OS and the Mutt Terminal based Email App installed and configured, I can send my clients stock analysis info using a OpenOffice Calc app I developed, regardless if it was run on a very expensive Mac, Windows PC or a fairly inexpensive Raspberry Pi 4b computer. I have included the intact Macro above because I have been frustrated over the past 8 years in not being able to get the Emailing code provided in this forum running on anything but Microsoft Windows based systems.
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
karolus
Volunteer
Posts: 1159
Joined: Sat Jul 02, 2011 9:47 am

Re: [Calc]Macro to Config,&Send Mail directly from OOffice

Post by karolus »

And Again Again…

Its easy enough to use on the Raspberry python for this task
https://docs.python.org/3/library/email.examples.html
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
alf50
Posts: 129
Joined: Sun Jun 13, 2010 2:55 pm

Re: [Calc]Macro to Config,&Send Mail directly from OOffice

Post by alf50 »

Karolus, I get it that Python could have been used. I also get that this forum’s intent is to teach people how to use the features of OpenOffice and LibreOffice without doing all the programming for them. The “Code Snippet” approach to teaching was very inefficient for me to pick up all the subtleties of OpenOffice Basic. Objects, .uno procedures, key word usage took a long time to pick up. Python is even worse. On a Mac, PC or Raspberry Pi device, you have to install libraries and learn the basics of terminal “command line” usage and stupid Python rules before you even get started. At least Mutt Email is a very straight forward to install and configuration (Follow the Numbers and you are done). My objective has always been to keep all the code associated with an application I am developing attached, ie directly associated with the sheet or app I am developing. No “My Python” libraries located somewhere in the Linux usr.etc… directory structure of my computer. That just leads to it working on your computer, but no one else’s.
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
Bidouille
Volunteer
Posts: 575
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: [Calc]Macro to Config,&Send Mail directly from OOffice

Post by Bidouille »

Another thread for a same problem: viewtopic.php?f=20&t=105848
:?:
Post Reply