I'm trying to sort out how to create an e-mail using OpenOffice Basic. I've sorted through what I think are most of the posts on this subject and keep getting some errors and unexpected behaviors. While I wouldn't necessarily expect my OpenOffice basic macro to force my default mail program to do anything it doesn't want to do, I'd at least like to replicate the behavior that I expect when I click a "mailto:" hyperlink within a document. If there is a way to force the body of the email, the recipient, and a list of To: e-mails into a new message as well, I'd like to do that, too! -- Also, I realize this is two questions and may have two entirely separate answers, but, one part of my brain (a naive part, perhaps) would like to think that the two questions are very closely related.
The current behavior of a "mailto:" hyperlink on my system: When I create a hyperlink, I can also specify the subject line (this is through the normal GUI). Once I click it, the default mail client opens a new message to the specified e-mail address and drops the subject line in place. I have multiple accounts in my mail client, but the mail client seems to pick the "From:" line on its own with no direction from OpenOffice. I assume this is the normal behavior.
The code below is how I've modified other similar snippets that are present in the forums. This one is closest to ZenLord's, but similar to many others.
This code runs without errors on my system. The only actions that occur, however, are that it causes the mail client to start and become the active window in the OS or else just become the active window in the OS if it is already running. It does not create any new mail message, unless somehow they are being created but are 'hidden' from the GUI of the OS or hidden from the GUI of the mail client.
Code: Select all
Sub Main
DIM MailClient, MailAgent, MailMessage AS Object
MailAgent = CreateUnoService("com.sun.star.system.SystemMailProvider")
MailClient = MailAgent.queryMailClient()
MailMessage = MailClient.createMailMessage()
MailMessage.Recipient = "someone@mailservice.net"
MailMessage.Subject = "This is a test Subject"
MailMessage.Originator = "me@mailservice.net"
MailMessage.Body = "This is a string placeholder for the text of the body of the email ... Signed, Dave"
MailClient.sendMailMessage(MailMessage, 0)
End Sub
If it is relevant: Apache OpenOffice 4.1.3, MacOS 10.12.4, Mail.app
--Please, I have seen that some responses to similar prior questions have asked the OP to change their default mail app. While that option may work, please note that my question above is two parts: first, can the behavior of clicking a "mailto:" hyperlink be duplicated with a Basic macro. It seems that this should be possible no matter the mail client, as long as a default mail client is specified in the OS. Second, if possible, can it be extended to include other basic parts of the message, like the body of the message.
Above is the gist of the question, but for more information about the project:
I'm not trying to spam anyone, but am monitoring a bunch of employees as to whether they are completing their work in a timely fashion. I would send this e-mail out after every week or so. So far the workbook and its programming can display a table (cells, cellrange) of who is overdue and by how much they are overdue but hides all the people who are up to date. After it provides that filtered table (cells, cellrange), I copy/paste that into an e-mail, then go back to Calc, select the list of associated e-mail addresses and then copy/paste those into the To: field. Works well, but as long as I'm writing a macros to make this process easier, I'd really like to see how easy I can make it!
Therefore, eventually, I'd like the body of the e-mail to automatically populate with a short message "Get your work done on time!" as well as the relevant table (cells/cellrange) containing how far overdue each person has become.
Thanks so much!
Dave