Page 1 of 1

[Solved] Basic Macro to send email

PostPosted: Wed Nov 06, 2019 4:36 pm
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   Expand viewCollapse view
     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

Re: Basic Macro to send email

PostPosted: Wed Nov 06, 2019 10:44 pm
by Zizi64
Some similar code works for me in my Libreoffice with the Thunderbird E-mail client.

Code: Select all   Expand viewCollapse view
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

Re: Basic Macro to send email

PostPosted: Sun Nov 10, 2019 2:30 pm
by Bidouille
Useless to have an external program like Thunderbird to do this.
AOO provide a dedicated service with com.sun.star.system.SystemMailProvider

Re: Basic Macro to send email

PostPosted: Mon Nov 11, 2019 12:52 pm
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.