Send email using a macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
simo1985
Posts: 3
Joined: Tue Jul 03, 2018 10:52 am

Send email using a macro

Post by simo1985 »

Hi, I want to send an email with a pdf attached with a macro in OpenOffice.
I searched in the forum and I found this lines:

Code: Select all

sub sendEmail
Dim eMailAddress as String
Dim eSubject as String
Dim eMailer as Object
Dim eMailClient as Object

eMailAddress =  "email@gmail.com"
eSubject = mailSubject
   eMailer = createUnoService("com.sun.star.system.SystemMailProvider")
   eMailClient = eMailer.queryMailClient()
   eMessage = eMailClient.createMailMessage()
   eMessage.Recipient = eMailAddress
   eMessage.Subject = "subject"
   eMessage.Body = "The text in the message"
   AttachmentURL = convertToUrl(URLDestinazione &  Sheet.getCellByPosition(0,currLine+primaRiga).string & ".pdf")
   eMessage.Attachement = Array(AttachmentURL)
   eMailClient.sendMailMessage ( eMessage, com.sun.star.system.MailClientFlags.NO_USER_INTERFACE )

End sub
The problem is that the program runs without any error, but it doesn't send the email: it just open my client email service and also doesn't fill the email, the subject and the body fields.
I tried both Mail(an Apple program) and Thunderbird with no results.
Can anyone help me?
OpenOffice version: 4.1.5
Operating system: MacOS High Sierra, version 10.13.3
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Send email using a macro

Post by Zizi64 »

Some similar code works fine for me on Windows 7 and with Thunderbird E-mail client. The Thunderbird must be set as the default email client.
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.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Send email using a macro

Post by Villeroy »

The built-in menu:File>Send Document as PDF works fine with Thunderbird and any mail provider that is connectable to it, including google mail.
The built-in mail merge feature can do this even without Thunderbird. It is tricky to set up but certainly easier than any macro code.
Python is an alternative macro language shipped with your office suite. It can help you to do anything you can think of.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply