Send email using a macro

Creating a macro - Writing a Script - Using the API

Send email using a macro

Postby simo1985 » Tue Jul 03, 2018 11:14 am

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   Expand viewCollapse view
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
simo1985
 
Posts: 3
Joined: Tue Jul 03, 2018 10:52 am

Re: Send email using a macro

Postby Zizi64 » Wed Jul 04, 2018 7:31 am

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; LO4.4.7, LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.4; AOO4.1.5
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
Zizi64
Volunteer
 
Posts: 7961
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Send email using a macro

Postby Villeroy » Wed Jul 04, 2018 12:05 pm

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26698
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests