Ask Your Question
0

Macro to send email to a specific address

asked 2016-09-20 12:59:50 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I have this: dispatcher.executeDispatch(document, ".uno:SendMailDocAsPDF", "", 0, Array())

But I want to send email to an address (hard-coded), like this: myemail@mydomain.com

Here's the whole macro I have now:

sub Send_As_PDF
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SendMailDocAsPDF", "", 0, Array())
end sub

(Edited for better readability; Lupp)

edit retag flag offensive close merge delete

Comments

I am afraid you won't get anywhere with this topic based on a recorded macro.
Did you already study 13.15.4 of "The Book" by Andrew Pitonyak, mainly the final Sub of the listing there? The book is availablel from this webpage. Also visit this page.
The MailMessage should also have a .Body property.

Lupp gravatar imageLupp ( 2016-09-20 14:36:24 +0200 )edit

I try to start with a recorded macro because I don't know about the object model. Often I can edit and tailor it to my needs afterward. But the book will be a huge help! Thanks very much.

LunixTheFirst gravatar imageLunixTheFirst ( 2016-09-20 22:24:07 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-04-18 15:48:35 +0200

librebel gravatar image

updated 2017-04-18 16:01:32 +0200

Hello dear fellow LibreOffice User, i don't know if it still matters at this time, but you could write:

Sub Send_As_PDF()
    Dim oFrame, oDispatch
    Dim aProps() As New com.sun.star.beans.PropertyValue
    AppendProperty( aProps(), "Recipient", "myemail@mydomain.com" )
    oFrame = ThisComponent.CurrentController.Frame
    oDispatch = createUnoService( "com.sun.star.frame.DispatchHelper" )
    oDispatch.executeDispatch( oFrame, ".uno:SendMailDocAsPDF", "", 0, aProps() )
End Sub

Sub AppendProperty( oProps(), sName As String, ByVal oValue )
    Dim oProperty As New com.sun.star.beans.PropertyValue
    Dim iLB As Integer, iUB As Integer
    oProperty.Name = sName
    oProperty.Value = oValue
    iLB = LBound( oProps() )
    iUB = UBound( oProps() ) + 1
    ReDim Preserve oProps( iLB To iUB )
    oProps(iUB) = oProperty
End Sub
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-09-20 12:59:50 +0200

Seen: 581 times

Last updated: Apr 18 '17