Page 1 of 1
Send email with attachment (LO)
Posted: Tue Jul 29, 2014 5:18 pm
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.
Re: Send email with attachment
Posted: Tue Jul 29, 2014 5:22 pm
by Villeroy
Re: Send email with attachment
Posted: Tue Jul 29, 2014 6:07 pm
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
Re: Send email with attachment
Posted: Tue Jul 29, 2014 6:34 pm
by Villeroy
Works for me with a valid declaration of the array.
The code pops up a Thunderbird window with the given address, subject and attachment.
Re: Send email with attachment
Posted: Wed Jul 30, 2014 11:32 am
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
Re: Send email with attachment
Posted: Wed Jul 30, 2014 2:56 pm
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
Re: Send email with attachment
Posted: Tue Aug 05, 2014 1:06 pm
by Villeroy
Here it works with LibreOffice 3.5. OpenOffice seems to have lost the mail stuff.
Re: Send email with attachment
Posted: Tue Aug 05, 2014 1:36 pm
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
Re: Send email with attachment
Posted: Tue Aug 05, 2014 1:40 pm
by Villeroy
Could you post a link to the bug, please?
Re: Send email with attachment
Posted: Tue Aug 05, 2014 3:04 pm
by dimpflmoser
Hi Villeroy,
I hope the link works that way ...
https://bugs.freedesktop.org/show_bug.cgi?id=82007
Cheers
Re: Send email with attachment (LO)
Posted: Sun Aug 10, 2014 10:52 pm
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.