Posted: Tue Apr 28, 2009 2:53 am Post subject: send email from macro with recipient, subject, attachement
Hello,
I need to send email with attachement, recipient and subject from a macro.
I can get this working with Openoffice.org 3.0.1 or 3.0 and Thunderbird.
In Tools>Options>Internet>Mail>Mail client, I write "/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin", if I only write "/Applications/Thunderbird.app", thunderbird opens on its mailboxes page, but doesn't open a new message.
I have to quit Thunderbird before sending a new mail, but I can work it out.
I use this kind of basic macro code :
Code:
sub sendMail( myPDFUrl, myRecipient, mySubject )
dim myService, myMail, myMessage
dim attachement(0)
attachement(0) = ConvertToURL( myPDFUrl )
myService = createUnoService("com.sun.star.system.SimpleSystemMail")
if isnull(myService) then
myService = createUnoService("com.sun.star.system.SimpleCommandMail")
endif
myMail = myService.querySimpleMailClient()
myMessage = myMail.createSimpleMailMessage()
with myMessage
.setOriginator("foo@bar.com")
.setrecipient(myRecipient)
.setsubject(mySubject)
.setattachement(attachement())
end with
myMail.sendSimpleMailMessage(monMessage,0)
end sub
With NeoOffice3, Thunderbird gets on, but stays on the mailboxes page, it doesn't open a new message. Eudora8 does the same.
With Mail.app, I get a new message containing the attachement, but recipient and subject are blanks. GyazMail does the same.
Could you please help me having this working on NeoOffice ?
Posted: Tue Apr 28, 2009 7:22 am Post subject: Re: send email from macro with recipient, subject, attacheme
edada wrote:
With NeoOffice3, Thunderbird gets on, but stays on the mailboxes page, it doesn't open a new message.
I have some bad news, this is caused by a limitation of Thunderbird. Unlike Apple's Mail application or Microsoft's Entourage application, sending Thunderbird a Mac OS X "open document" event will only make Thunderbird the application and Thunderbird will ignore the document that NeoOffice sends it.
This Thunderbird limitation has existed even when Firefox and Thunderbird were called Mozilla so I don't expect that Mozilla.org is likely to ever add this feature.
There is more information about this issue, including a link to the bug report for Thunderbird, in the following NeoWiki article Selecting your preferred mail client.
edada wrote:
I can get this working with Openoffice.org 3.0.1 or 3.0 and Thunderbird.
I can get this working with OOo 3 and Thunderbird on MacOS !
with 10.5 today, and I also had good results with 10.4 few month ago.
As I said, if I write '/Apllications/Thunderbird.app' in the email client option, I don't get a new message, just the mailboxes window. But if I write there '/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin', Thunderbird open a new message, which can come with recipient, subject and attachment given by OOo.
Tested with Thunderbird 2.0.0.18 and 2.0.0.21.
I will finally use an external script which will close Thunderbird if needed, and launch Thunderbird with the -compose option to prepare a complete mail.
I can get this working with OOo 3 and Thunderbird on MacOS !
with 10.5 today, and I also had good results with 10.4 few month ago.
As I said, if I write '/Apllications/Thunderbird.app' in the email client option, I don't get a new message, just the mailboxes window. But if I write there '/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin', Thunderbird open a new message, which can come with recipient, subject and attachment given by OOo.
I am sorry to give you the bad news, but what you are trying to do will not work in NeoOffice. Unlike OpenOffice.org, NeoOffice communicates with other applications using teh standard Mac way of sending application events. In the case of e-mail, NeoOffice sends your selected e-mail application an "open document" event.
In contrast, OpenOffice.org uses the Windows/Linux method of launching an e-mail application from the command line with command line arguments to pass the recipient, subject, etc. Unfortunately, using the standard Mac application events way, there is no way to emulate the passing of command line arguments so the recipient, subject, etc. will never be passed to the target application in NeoOffice.
While it may seem strange for NeoOffice to use the native Mac application events approach rather the Windows/Linux command line approach, we switched to the Mac application events approach long ago as it made NeoOffice more compatible with the two most often used mail applications on the Mac: Apple Mail and Microsoft Entourage.
we switched to the Mac application events approach long ago as it made NeoOffice more compatible with the two most often used mail applications on the Mac: Apple Mail and Microsoft Entourage.
Hum, using the above starbasic macro, I get exactly the same result from Mail.app with OOo3 or NeoOffice3 -> only attachment is passed. I don't own Entourage.
Anyway, I got a workaround with external shell script for sending mail with Thunderbird from a macro, it can send body too, that was not possible using com.sun.star.system.Simple(System|Command)Mail. It's not cross-platform. My sendMail sub now looks like this :
Code:
sub sendMail( myPDFUrl, myRecipient, mySubject, myBody )
' we use a script that is stored in the same directory than the odb file, lets find its path :
Dim DataSource As Object
DataSource = createUnoService("com.sun.star.sdb.DatabaseContext").getByName("TheDataBase")
dim myPath as string
myPath = ConvertFromURL( DirectoryNameoutofPath(DataSource.DatabaseDocument.URL, "/") )
'we prepare the params that we will give to thunderbird
dim myParams as string
myParams = "-compose to=" & myRecipient & ",subject=" & mySubject & ",body=" & join(split(join(split(myBody,","),"%2C"),chr(10)),"%0A") & ",attachment='" & ConvertToURL( myPDFUrl ) & "'"
'at least commas and newlines must be escaped in the body, I believe lots of other things should be escaped, becareful
Shell( myPath & "/launchTB.sh " & myParams )
end sub
And in the same folder than my database file, there is an executable shell script "launchTB.sh":
Code:
#!/bin/bash
if ps ax | grep -v grep | grep thunderbird-bin > /dev/null
then
osascript -e 'tell application "Thunderbird.app"' -e 'quit' -e 'end tell'
fi
/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin $*
The firsts lines cleanly quit Thunderbird, I don't know how to open a new message in an already opened Thunderbird. The last line reopen Thunderbird with all good params we prepared in the macro. If someone comes with a better solutions, I'll be glad to know !)
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum