Send email with attachment (LO)

Keyboard macros or custom scripts

Send email with attachment (LO)

Postby dimpflmoser » Tue Jul 29, 2014 5:18 pm

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

Re: Send email with attachment

Postby Villeroy » Tue Jul 29, 2014 5:22 pm

Linux?
Code: Select all   Expand viewCollapse view
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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28674
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Send email with attachment

Postby dimpflmoser » Tue Jul 29, 2014 6:07 pm

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   Expand viewCollapse view
' 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
dimpflmoser
 
Posts: 10
Joined: Sat Jul 26, 2014 3:27 pm

Re: Send email with attachment

Postby Villeroy » Tue Jul 29, 2014 6:34 pm

Works for me with a valid declaration of the array.
Code: Select all   Expand viewCollapse view
      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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28674
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Send email with attachment

Postby dimpflmoser » Wed Jul 30, 2014 11:32 am

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

Postby dimpflmoser » Wed Jul 30, 2014 2:56 pm

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   Expand viewCollapse view
objMailClient = objMail.querySimpleMailClient()


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

Re: Send email with attachment

Postby Villeroy » Tue Aug 05, 2014 1:06 pm

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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28674
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Send email with attachment

Postby dimpflmoser » Tue Aug 05, 2014 1:36 pm

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

Re: Send email with attachment

Postby Villeroy » Tue Aug 05, 2014 1:40 pm

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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28674
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Send email with attachment

Postby dimpflmoser » Tue Aug 05, 2014 3:04 pm

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

Re: Send email with attachment (LO)

Postby vladboscaneanu » Sun Aug 10, 2014 10:52 pm

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
vladboscaneanu
 
Posts: 32
Joined: Wed Apr 30, 2014 2:08 am


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 5 guests