[Calc] Automatically create and send mail

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

[Calc] Automatically create and send mail

Post by alf50 »

Want to fully automate a LibraOffice Calc App I am developing (and trying to get it to run on a Raspberry Pi4b-8GB computer). One part of it is to send out an Email Message telling me it has successfully process a file. I can create a the Email Message and send it to my Mail Client using aHTML = "Mail To:" function, but have not been able to figure out how to tell my mail client to send the message without me being there to click the send button. The Code follows:

Code: Select all

Sub SimpleMailTo  
Dim launcher as object
Dim eAddress, eSubject, eBody, CCeAddr, BCCeAddr, aHTMLanchor as string

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

eAddress = "Me1@gmail.com"
CCeAddr = "Me2@gmail.com"
BCCeAddr = ""
eSubject = "PDFgen App run from RasPi4"
ebody = "PDFgen App run from RasPi4-8GB"

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

launcher.execute(aHTMLanchor, "", 0)

End Sub
Is there something that I can put in the launcher.execute(aHTMLanchor, "", 0) that will tell the mail app to send without prompting? Or is there some kind of separate Macro that would tell the Mail.app to send the top window after it receives the email?
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
Zizi64
Volunteer
Posts: 11345
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Calc Macro to Config, send to mail app&Send out wo inter

Post by Zizi64 »

but have not been able to figure out how to tell my mail client to send the message without me being there to click the send button.
viewtopic.php?f=20&t=89073
viewtopic.php?f=45&t=99927

Code: Select all

eMailClient.sendSimpleMailMessage ( eMessage,com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE ) 
End Sub
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] Automatically create and send mail

Post by Villeroy »

With a true programming language this would be a trivial task. You don't need any mail client, let alone any office suite. All you need is access to a valid mail account.

Example: viewtopic.php?f=21&t=90298
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
alf50
Posts: 128
Joined: Sun Jun 13, 2010 2:55 pm

Re: [Calc] Automatically create and send mail

Post by alf50 »

I pasted the code from one of your links but I get the "Basic RunTime Error: Object Variable Not Set". What is wrong here? The Code and the line giving the error are shown below.

Code: Select all

sub SendAlert
Dim eMailAddress, eSubject as string
Dim eMailer as object
Dim eMailClient as object
Dim eMessage as object

eMailAddress = "Me2@gmail.com"
eSubject = "PDFgen App run from RasPi 4B"
eMailer = createUnoService("com.sun.star.system.SimpleSystemMail")
'------------------------------------
' This line gives the Error: Basic Runtime error: "Object Variable Not Set" What is wrong here?
eMailClient = eMailer.querySimpleMailClient()
'------------------------------------
eMessage = eMailClient.createSimpleMailMessage()

eMessage.Recipient = eMailAddress
eMessage.Subject = eSubject
eMessage.Body = "PDFgen App run from RasPi 4B"  'temporary whilst testing
AttachmentURL = convertToUrl("home\Pi\Desktop\DTop\RPi-F.txt")
eMessage.Attachement = array(AttachmentURL)
eMailClient.sendSimpleMailMessage ( eMessage, com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE )
End Sub
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
RoryOF
Moderator
Posts: 34570
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Calc] Automatically create and send mail

Post by RoryOF »

There may be helpful information in this thread

viewtopic.php?f=9&t=58462
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] Automatically create and send mail

Post by Villeroy »

My Python macro works pretty well.
Enter your SMTP data, install it, create a 3 column list on sheet with address, subject, text, select the list and call macro pyCalc/range2smtp/sendMailFromRangeSelection
It logs into the server, reads the 3 column range and sends email with 5 seconds pause between each row. The only part in the code which has anything to do with Calc reads the 3 column data from the range selection.
You may get 2 different error messages from that macro. One contains 'Server Error. Check the SMTP settings in this Python module'. The other one contains 'DataArray Error. No 3-column range selected.'
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
alf50
Posts: 128
Joined: Sun Jun 13, 2010 2:55 pm

Re: [Calc] Automatically create and send mail

Post by alf50 »

zizi64: No matter which of your example links I try to use, when I get to this line of code:

eMailClient = eMailer.querySimpleMailClient()

This line gives the Error: Basic Runtime error: "Object Variable Not Set".

I set eMailClient and eMailer as objects

What am I not seeing here???
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
Zizi64
Volunteer
Posts: 11345
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Calc] Automatically create and send mail

Post by Zizi64 »

zizi64: No matter which of your example links I try to use, when I get to this line of code:

eMailClient = eMailer.querySimpleMailClient()

This line gives the Error: Basic Runtime error: "Object Variable Not Set".

I set eMailClient and eMailer as objects

What am I not seeing here???
I do not know it.

I used the linked code in LibreOffice, on Windows (7 and 10) and with the installed Thunderbird (default) e-mail client.
(The code controls the default system mail client.)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] Automatically create and send mail

Post by Villeroy »

Inspect your Basic variables using stop marks, step mode and the variable watch window. Your eMailer is a Null value. Don't ask me why, but at some point you need access to some SMTP server. Where is SimpleSystemMail supposed to get its login credentials?
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
alf50
Posts: 128
Joined: Sun Jun 13, 2010 2:55 pm

Re: [Calc] Automatically create and send mail

Post by alf50 »

I am running LibraOffice on a Raspberry Pi 4b using the Twister OS. I captured the following Macros in Libra Basic using the Record function:

Code: Select all

sub SEmailooc
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SendMailDocAsOOo", "", 0, Array())


end sub


sub SEmailpdf
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SendMail", "", 0, Array())


end sub
This code works perfectly with the OO Email Preferences set to use the default Twister OS Email Client App (I think it is called "Mail Reader"). SEmailooc was recorded while selecting the Send E-mail of the OpenOffice Calc Spreadsheet that I was working on. As you can see, the parameters used to specify the recipients email address and Subject line are not shown in the recorded macro.

The second macro, Emailpdf, used the Send E-mail Document selection, that also allowed me to select a document where I had to browse the File system and select the file I wanted to added to the Email. As you can see again, the parameters used to specify the recipients email address, Subject line and path to the added file are not shown in the recorded macro.

Those Email Element are probably specified in the Array() variable seen on the code line:

dispatcher.executeDispatch(document, ".uno:SendMail", "", 0, Array())

Can anyone tell me how to setup that Array() to include the Recipient Email Address, Subject line, body text, and url path to the document I selected to include in the email? It appears that the ".uno:SendMailDocAsOOo" and ".uno:SendMail" use the Default Mail Client sender name and password credentials to send properly through gmail.

This is the first time in years that emailing directly out of an OpenOffice/LibraOffice Calc document has worked for me without security/Mail Server Link ERROR issues.
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] Automatically create and send mail

Post by Villeroy »

You know where the "Pi" in "Raspberry Pi" comes from? Python Interpreter. Instead you load a multi-Megabyte office suite to send mail?

https://www.techspot.com/article/531-eb ... interview/
Eben Upton wrote:Pi is because originally we were going to produce a computer that could only really run Python. So the Pi in there is for Python.
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
alf50
Posts: 128
Joined: Sun Jun 13, 2010 2:55 pm

Re: [Calc] Automatically create and send mail

Post by alf50 »

Villeroy, I have no desire to use Python. I have used Python for controlling a Radio Controlled car that I built but I prefer LibraOffice Basic for OpenOffice Calc apps. Stop trying to push Python for everything. But, thank you for your support and expertise. They are invaluable in helping others.
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
Zizi64
Volunteer
Posts: 11345
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Calc] Automatically create and send mail

Post by Zizi64 »

Stop trying to push Python for everything.
The OpenOffice and LibreOffice supports more than one programming languages.

- StarBasic (Basic, OpenOffice Basic, LibreOffice Basic): it has built-in IDE, debugger, etc...
- Python: It is a more modern language (than the Basic) with lots of available (existing) programming libraries for various tasks.
- JavaScript
- BeanShell

Of course they will be suggested when your task is more achievable by usage of one or other. Feel free to choose the less adequate programming language. (In another words: choose that what you know better.)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
RoryOF
Moderator
Posts: 34570
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Calc] Automatically create and send mail

Post by RoryOF »

alf50 wrote:Villeroy, I have no desire to use Python. I have used Python for controlling a Radio Controlled car that I built but I prefer LibraOffice Basic for OpenOffice Calc apps. Stop trying to push Python for everything. But, thank you for your support and expertise. They are invaluable in helping others.
Sometimes the best solution is not what one expected. Use of the correct libraries in Python might simplify your problem to a very few lines of code, which in OpenOffice BASIC could involve having to write an entire equivalent library.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
alf50
Posts: 128
Joined: Sun Jun 13, 2010 2:55 pm

Re: [Calc] Automatically create and send mail

Post by alf50 »

So, if I understand correctly, no one knows how the:

.uno:SendMail routine call gets data from the:

"File-Send-E-Mail Document..." File Menu Routine.

Is there any help documentation for the .uno:SendMail Routing that I can access?
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] Automatically create and send mail

Post by Villeroy »

menu:File>Send>Email... passes the current document to the system wide mail client which of course knows how to send your mail. I recall that there used to be some wizard where you had to specify SMTP settings in order to do mail merge via SMTP. These credentials were stored in the profile and in plain text.

There is still a remainder in my registrymodifications.xcu:

Code: Select all

<item oor:path="/org.openoffice.Office.Writer/MailMergeWizard"><prop oor:name="IsSMPTAfterPOP" oor:op="fuse"><value>false</value></prop></item>
<item oor:path="/org.openoffice.Office.Writer/MailMergeWizard"><prop oor:name="IsSecureConnection" oor:op="fuse"><value>true</value></prop></item>
<item oor:path="/org.openoffice.Office.Writer/MailMergeWizard"><prop oor:name="MailAddress" oor:op="fuse"><value>villeroy@provider.de</value></prop></item>
<item oor:path="/org.openoffice.Office.Writer/MailMergeWizard"><prop oor:name="MailDisplayName" oor:op="fuse"><value>Villeroy</value></prop></item>
<item oor:path="/org.openoffice.Office.Writer/MailMergeWizard"><prop oor:name="MailPassword" oor:op="fuse"><value>OpenPassword</value></prop></item>
<item oor:path="/org.openoffice.Office.Writer/MailMergeWizard"><prop oor:name="MailPort" oor:op="fuse"><value>465</value></prop></item>
<item oor:path="/org.openoffice.Office.Writer/MailMergeWizard"><prop oor:name="MailReplyTo" oor:op="fuse"><value></value></prop></item>
<item oor:path="/org.openoffice.Office.Writer/MailMergeWizard"><prop oor:name="MailServer" oor:op="fuse"><value>provider.de</value></prop></item>
<item oor:path="/org.openoffice.Office.Writer/MailMergeWizard"><prop oor:name="MailUserName" oor:op="fuse"><value>villeroy@provider.de</value></prop></item>
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
alf50
Posts: 128
Joined: Sun Jun 13, 2010 2:55 pm

Re: [Calc] Automatically create and send mail

Post by alf50 »

Here is the attempt to correct the "Object Variable Not Set Error" using the SendMail .uno, but it still does not work.

Code: Select all

sub SEmailpdf
rem define variables
Dim sAttachmentURL, sEmailAddress, sMessageBody as string
Dim CCeAddr, BCCeAddr, eSubject as string
Dim eMailer as Object
Dim eMailClient as Object
Dim eMessage as Object
rem define variables
Dim document   as object
Dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------

   sAttachmentURL= convertToUrl("home\Pi\Desktop\DTop\RPi-F.txt")
   sEmailAddress= "Me2@gmail.com"
   sSubject= "PDFgen App run from RasPi 4B"
   sMessageBody= "PDFgen App run from RasPi 4B at time of send."
   
rem -------- Tried both ways to create the service, both ways failed ----
'   eMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )
   eMailer = createUnoService( "com.sun.star.system.SendMail" )

rem --------Here is where the macro always fails with a 
rem -- "Object variable not set error"...\/ \/

'   eMailClient = eMailer.querySimpleMailClient()
   eMailClient = eMailer.querySendMail()
rem ----------------------------------------------------------------------

'   eMessage = eMailClient.createSimpleMailMessage()   
   eMessage = eMailClient.createSendMail()   
      eMessage.setRecipient(sEmailAddress)
      eMessage.setSubject(sSubject)
      eMessage.setAttachement (Array(sAttachmentURL))
      eMessage.body = sMessageBody
rem ----------------------------------------------------------------------
 eMailClient.SendMail( eMessage, 0 ) 
'  dispatcher.executeDispatch(document, ".uno:SendMail", "", 0, Array())

end sub
Here is the original way I tried that gives the same error.

Code: Select all

Sub send_email

Dim sAttachmentURL, sEmailAddress, sMessageBody as string
Dim CCeAddr, BCCeAddr, eSubject as string
Dim eMailer as Object
Dim eMailClient as Object
Dim eMessage as Object

   sAttachmentURL= convertToUrl("home\Pi\Desktop\DTop\RPi-F.txt")
   sEmailAddress= "Me2@gmail.com"
   sSubject= "PDFgen App run from RasPi 4B"
   sMessageBody= "PDFgen App run from RasPi 4B at time of send."
   eMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )
   eMailClient = eMailer.querySimpleMailClient()
   eMessage = eMailClient.createSimpleMailMessage()   
      eMessage.setRecipient(sEmailAddress)
      eMessage.setSubject(sSubject)
      eMessage.setAttachement (Array(sAttachmentURL))
      eMessage.body = sMessageBody

   eMailClient.sendSimpleMailMessage( eMessage, 0 ) 
'	if you want to handle the sending manually in the mail client software
'   eMailClient.sendSimpleMailMessage ( eMessage,com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE ) 'Silent sending
End Sub
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
Zizi64
Volunteer
Posts: 11345
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Calc] Automatically create and send mail

Post by Zizi64 »

Here is the original way I tried that gives the same error.

Code: Select all

Code: Select all   Expand view
    Sub send_email

    Dim sAttachmentURL, sEmailAddress, sMessageBody as string
    Dim CCeAddr, BCCeAddr, eSubject as string
    Dim eMailer as Object
    Dim eMailClient as Object
    Dim eMessage as Object

       sAttachmentURL= convertToUrl("home\Pi\Desktop\DTop\RPi-F.txt")
       sEmailAddress= "Me2@gmail.com"
       sSubject= "PDFgen App run from RasPi 4B"
       sMessageBody= "PDFgen App run from RasPi 4B at time of send."
       eMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )
       eMailClient = eMailer.querySimpleMailClient()
       eMessage = eMailClient.createSimpleMailMessage()   
          eMessage.setRecipient(sEmailAddress)
          eMessage.setSubject(sSubject)
          eMessage.setAttachement (Array(sAttachmentURL))
          eMessage.body = sMessageBody

       eMailClient.sendSimpleMailMessage( eMessage, 0 )
    '   if you want to handle the sending manually in the mail client software
    '   eMailClient.sendSimpleMailMessage ( eMessage,com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE ) 'Silent sending
    End Sub
This code (the attachment URL and the mail address is actualized to my environment) works for me on Win10 with Thunderbird default email client. It works the silent and the non-silent sending too.
(LibreOffice 6.1.6)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
alf50
Posts: 128
Joined: Sun Jun 13, 2010 2:55 pm

Re: [Calc] Automatically create and send mail

Post by alf50 »

Zizi64: Is it possible that I have to load a special Global Tools Library so that the Macro can handle processing the:
"eMailClient = eMailer.querySimpleMailClient()" command line? Could that Library be loaded with the OpenOffice Sweet on your Windows 10 Pro machine, but is not loaded on the Mac or Raspberry Pi computers I am using.

An example of this occures when I want to get the path to the document I currently have open. I must load the Global Library:
GlobalScope.BasicLibraries.loadLibrary("Tools")

before I use the DirectoryNameoutofPath(ThisComponent.getURL(),"/") command:

CpathNm=DirectoryNameoutofPath(ThisComponent.getURL(),"/")
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
Zizi64
Volunteer
Posts: 11345
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Calc] Automatically create and send mail

Post by Zizi64 »

The Tools library seems has not been loaded in my LibreOffice. (Its color is not yellow in the Object Catalog of the code editor.)

But you can try to load it by a few lines of code:

Code: Select all

If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then
		GlobalScope.BasicLibraries.LoadLibrary("Tools")
	End If
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: [Calc] Automatically create and send mail

Post by Bidouille »

Useless to have an external program like Thunderbird to do this.
AOO provide a dedicated service with com.sun.star.system.SystemMailProvider
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] Automatically create and send mail

Post by Villeroy »

Code: Select all

Function getURLStruct(sURL AS String)
srv = createUnoService("com.sun.star.util.URLTransformer")
url = createUnoStruct("com.sun.star.util.URL")
oURL = srv.parseStrict(sURL)
getURLStruct = oURL
End Function
Returns https://api.libreoffice.org/docs/idl/re ... _1URL.html

Code: Select all

myFileURLString = ThisComponent.getURL()
myURL = getURLStruct(myFileURLString)
sPath = myURL.Protocol & myURL.Path
print sPath
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: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] Automatically create and send mail

Post by Villeroy »

Bidouille wrote:Useless to have an external program like Thunderbird to do this.
AOO provide a dedicated service with com.sun.star.system.SystemMailProvider
Where does this service get its SMTP configuration?
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
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: [Calc] Automatically create and send mail

Post by RPG »

try this

Code: Select all

    sub SEmailpdf
    rem define variables
    Dim sAttachmentURL, sEmailAddress, sMessageBody as string
    Dim CCeAddr, BCCeAddr, eSubject as string
    Dim eMailer as Object
    Dim eMailClient as Object
    Dim eMessage as Object
    rem define variables
    Dim document   as object
    Dim dispatcher as object
    rem ----------------------------------------------------------------------
    rem get access to the document
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

    rem ----------------------------------------------------------------------

       sAttachmentURL= convertToUrl("home\Pi\Desktop\DTop\RPi-F.txt")
       sEmailAddress= "Me2@gmail.com"
       sSubject= "PDFgen App run from RasPi 4B"
       sMessageBody= "PDFgen App run from RasPi 4B at time of send."
       
    rem -------- Tried both ways to create the service, both ways failed ----
eMailer = createUnoService( "com.sun.star.system.SimpleCommandMail" )' use this when you use libreoffice and when it is linux and maybe MAC
'      eMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" ) ' use this when you use libreoffice
'       eMailer = createUnoService( "com.sun.star.system.SendMail" )

    rem --------Here is where the macro always fails with a
    rem -- "Object variable not set error"...\/ \/

       eMailClient = eMailer.querySimpleMailClient() ' use this when you use libreoffice
       ' you do get an error when it is 
    '   eMailClient = eMailer.querySendMail()
    rem ----------------------------------------------------------------------

     eMessage = eMailClient.createSimpleMailMessage()    'use this when you use libreoffice
  '     eMessage = eMailClient.createSendMail()   
          eMessage.setRecipient(sEmailAddress)
          eMessage.setSubject(sSubject)
          eMessage.setAttachement (Array(sAttachmentURL))
          eMessage.body = sMessageBody
    rem ----------------------------------------------------------------------
 '   eMailClient.SendMail( eMessage, 0 )
eMailClient.sendSimpleMailMessage( eMessage, 0 ) ' use this for libreoffice linux
    '  dispatcher.executeDispatch(document, ".uno:SendMail", "", 0, Array())
    end sub
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: [Calc] Automatically create and send mail

Post by Bidouille »

Villeroy wrote:Where does this service get its SMTP configuration?
Ariel give a sample document to set it:
Attachments
Server_Timeout.odt
(19.63 KiB) Downloaded 277 times
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] Automatically create and send mail

Post by Villeroy »

Bidouille wrote:
Villeroy wrote:Where does this service get its SMTP configuration?
Ariel give a sample document to set it:
Thank you very much. It feels good to read some professional code from time to time.
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
Post Reply