[Solved] Basic Macro to send email

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Nelomf
Posts: 22
Joined: Wed Nov 06, 2019 4:29 pm

[Solved] Basic Macro to send email

Post by Nelomf »

Hello

I'm new with openoffice and i'm trying to send one active Calc file to Thunderbird as attachment

the code i have wrote is the following:

Code: Select all

     Dim Path As String
     Dim thund As String
     Dim email As String
     Dim subj As String
     Dim body As String
 
     email = "my email"
     subj = "Teste"
     body = "Teste envio"
     Path = "D:\Compras\Encomendas 2020.ods"
 
     thund = "C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe " & _
             "-compose " & """" & _
             "to='" & email & "'," & _
             "cc='" & cc & "'," & _
             "bcc='" & bcc & "'," & _
             "subject='" & subj & "'," & _
             "body='" & body & "'" & """"
            
    
  If Path = "" Then 'no attachment
                'do nothing

             Else 'with attachment
                thund = thund & ",attachment=" & Path
                End If 
 
     Call Shell(thund, vbNormalFocus)

All works fine except the attachment.
This macro is linked to a push button on my sheet.

Tks for the help
Manuel
Last edited by Hagar Delest on Tue Nov 12, 2019 12:37 pm, edited 2 times in total.
Reason: tagged solved
Openoffice 4, Windows 7
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Basic Macro to send email

Post by Zizi64 »

Some similar code works for me in my Libreoffice with the Thunderbird E-mail client.

Code: Select all

REM  *****  BASIC  *****

Sub send_email(sAttachmentURL as string, sEmailAddress as string, sSubject as string, sMessageBody as string)

 Dim eMailer as Object
 Dim eMailClient as Object
 Dim eMessage as Object
	
	eMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )
	eMailClient = eMailer.querySimpleMailClient()     
	eMessage = eMailClient.createSimpleMailMessage()    
		eMessage.setRecipient(sMailAddress)
		eMessage.setSubject(sSubject)
		eMessage.setAttachement (Array(sAttachmentURL))
		eMessage.body = sMessageBody

	eMailClient.sendSimpleMailMessage( eMessage, 0 ) 'if you want to handle the sending manually in the mail client software
'	eMailClient.sendSimpleMailMessage ( eMessage,com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE ) 'Silent sending
End Sub
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Bidouille
Volunteer
Posts: 577
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Basic Macro to send email

Post by Bidouille »

Useless to have an external program like Thunderbird to do this.
AOO provide a dedicated service with com.sun.star.system.SystemMailProvider
Nelomf
Posts: 22
Joined: Wed Nov 06, 2019 4:29 pm

Re: Basic Macro to send email

Post by Nelomf »

Bidouille wrote:Useless to have an external program like Thunderbird to do this.
AOO provide a dedicated service with com.sun.star.system.SystemMailProvider
Tks
I follow the link and i got the solution in one of the posts.
Openoffice 4, Windows 7
Post Reply