I have made a bit of progress, but it is still not doing what I want.
I used the macro recorder to capture the sequence of sending the current document as a pdf, the tried embellishing the code. What I have so far is this:
sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
dim args(3) As New com.sun.star.beans.PropertyValue
rem ----------------------------------------------------------------------
args(0).Name = "From:"
args(0).Value = "someone@gmail.com"
args(1).Name = "To:"
args(1).Value = "someone_else@gmail.com"
args(2).Name = "Subject:"
args(2).Value = "Here is your document"
args(3).Name = "Message:"
args(3).Value = "Thank you for your enquiry."
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SendMailDocAsPDF", "", 0, args())
end sub
Two problems remain:
- The PDF dialog is presented: I want to silently accept its defaults.
- I have no idea what the correct argument names are for providing the source email, destination email, subject and message body to the mail client (Evolution). My guesses did not work.
I would really appreciate any ides on how to progress this macro. "
Kind regards,
Doug
---------------- Later -------------------
I have also tried this angle:
Sub subSendEmail
Dim objThisMessage as Object
objThisMessage = createUnoService("com.sun.star.mail.MailMessage")
objThisMessage.addRecipient("someone@gmail.com")
objThisMessage.SenderName = "A Name"
objThisMessage.SenderAddress = "abpa@nowhere.com"
objThisMessage.ReplyToAddress = objThisMessage.SenderAddress
objThisMessage.Subject = "This is a test email."
objThisMessage.Body = "Thank you for playing."
End Sub
The problems with this are:
-
Sender name and address are read-only attributes. On the target system, Evolution manages several different email accounts and the one to be used with this code is not the default, so it is vital I can set the sender details from BASIC.
-
Even if I could create the email the way I want it, how do I send it? com::sun::mail offers the SendMailMessageFailedException, but no ‘send’ method. The com::sun::system::XSimpleMailClient Interface offers sendSimpleMailMessage(), but I don’t see anything similar in com.sun.star.mail.MailMessage
Still bashing my head against the wall …
------------------- Later still ---------------------
This also fails, with createUnoService silently creating a null object:
Sub subSimpleMailAttempt
Dim objClient As Object
Dim objMessage As Object
objClient = createUnoService("com.sun.star.system.SimpleSystemMail")
objMessage = objClient.createSimpleMailMessage()
objMessage.setRecipient("someone@somewhere.com")
End Sub
I have found the services and interfaces I need and will ask a new question about them.
------------------- Later ----------------------
I found SimpleSystemMail does not seem to be implemented. The following code works, except the sender does not get set to the originator I specify. Still, it is major progress:
Sub subSimpleMailAttempt
Dim objClient As Object
Dim objMessage As Object
objClient = createUnoService("com.sun.star.system.SimpleCommandMail")
objMessage = objClient.createSimpleMailMessage()
objMessage.setRecipient("someone@gmail.com")
objMessage.setOriginator("an_account@gmail.com>")
objMessage.setSubject("This is your raffle ticket")
objMessage.Body = "Arnold"
objClient.sendSimpleMailMessage (objMessage, 2)
End Sub