Send email with attachment (LO)

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
dimpflmoser
Posts: 10
Joined: Sat Jul 26, 2014 3:27 pm

Send email with attachment (LO)

Post by dimpflmoser »

Hello everybody,

I need to send an email with an attachment from my basic code. From the Base handbook I found this code:

Code: Select all

objShell = createUnoService("com.sun.star.system.SystemShellExecute")
objShell.execute("mailto:" & strEmailAddress & "?subject=" & strSubject & "?attachment=" & strDateiName,,0)
The problem is, that "mailto" does not allow attachments (?) - what happens is that "?attachment=" & strDateiName" and the name and path of the file is displayd in the subject field.

So I wonder whether it is possible to send an email with attachment via basic and if so, whether anybody can supply a piece of example code?

Thanks and regards

P.S. The code should work on Win, Linux and Mac - as we have all three operating systems in our team.
LibreOffice 4.2 on Ubuntu 14.04
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Send email with attachment

Post by Villeroy »

Linux?

Code: Select all

man mail
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
dimpflmoser
Posts: 10
Joined: Sat Jul 26, 2014 3:27 pm

Re: Send email with attachment

Post by dimpflmoser »

Hello again,

by searching the web I found the following code - sadly it does not attach the document (so far tested on Ubuntu 14.04 with Thunderbird as email client):

Code: Select all

' Testen, ob Windows
		If GetGuiType() = 1 Then
			objMail = createUnoService("com.sun.star.system.SimpleSystemMail")
		' Sonst Liux/Mac
		Else
			objMail = createUnoService("com.sun.star.system.SimpleCommandMail")
		End If
		' Zugriff auf Mail-Client-Programm
		objMailClient = objMail.querySimpleMailClient()
		' Message-Objekt erstellen
		objMessage = objMailClient.createSimpleMailMessage()
		' Nachrichtenempfänger setzen
		objMessage.setRecipient(strEmailAddress)
		' Betreff setzen
		objMessage.setSubject(strSubject)
		' Aktuelles Dokument als Anhang
		mAttachment(0) = ConvertToURL(strDateiName)
		objMessage.setAttachement(mAttachment())
		' MailClient öffnen
		objMailClient.sendSimpleMailMessage(objMessage, 0)
Thanks again
LibreOffice 4.2 on Ubuntu 14.04
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Send email with attachment

Post by Villeroy »

Works for me with a valid declaration of the array.

Code: Select all

      Dim mAttachment(0)
The code pops up a Thunderbird window with the given address, subject and attachment.
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
dimpflmoser
Posts: 10
Joined: Sat Jul 26, 2014 3:27 pm

Re: Send email with attachment

Post by dimpflmoser »

Hello again,

thanks for your answer. The attachment array is declared exactly that way.

I've just tested the code on ubuntu 12.04, LibreOffice 3.6 and Thunderbird 31 where it does its Job perfectly. The thunderbird version is identical. So there must be some kind of issue either with ubuntu 14.04 and/or LibreOffice 4.2.x.

I will check on windows and thunderbird.

Any ideas?

Thanks again
LibreOffice 4.2 on Ubuntu 14.04
dimpflmoser
Posts: 10
Joined: Sat Jul 26, 2014 3:27 pm

Re: Send email with attachment

Post by dimpflmoser »

Hello again,

I've just tried to run the application on Apache OpenOffice 4.1.0. and found out that the following line from the above code produces a "object variable not set(?)" (Objektvariable nicht belegt) - error:

Code: Select all

objMailClient = objMail.querySimpleMailClient()
Thanks and regards
LibreOffice 4.2 on Ubuntu 14.04
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Send email with attachment

Post by Villeroy »

Here it works with LibreOffice 3.5. OpenOffice seems to have lost the mail stuff.
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
dimpflmoser
Posts: 10
Joined: Sat Jul 26, 2014 3:27 pm

Re: Send email with attachment

Post by dimpflmoser »

Hello Villeroy,

thanks for your reply. Yes it seems to be kind of bug in LO 4.x on Linux - I checked the above code with LO 4.3 and thunderbird on Win 7 where it works without problems.

I've posted a bug report to LO.

Cheers
LibreOffice 4.2 on Ubuntu 14.04
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Send email with attachment

Post by Villeroy »

Could you post a link to the bug, please?
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
dimpflmoser
Posts: 10
Joined: Sat Jul 26, 2014 3:27 pm

Re: Send email with attachment

Post by dimpflmoser »

Hi Villeroy,

I hope the link works that way ...

https://bugs.freedesktop.org/show_bug.cgi?id=82007

Cheers
LibreOffice 4.2 on Ubuntu 14.04
vladboscaneanu
Posts: 32
Joined: Wed Apr 30, 2014 2:08 am

Re: Send email with attachment (LO)

Post by vladboscaneanu »

Hi people!
I have had the same problem in the past:so,if I understood well,the service
com.sun.star.system.SimpleCommandMail
is no more exists in AOO version 4 and later.
Hope this help you.
LibreOffice last version on Windows 10
Post Reply