Page 1 of 1

Send email using a macro

PostPosted: Tue Jul 03, 2018 11:14 am
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   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?

Re: Send email using a macro

PostPosted: Wed Jul 04, 2018 7:31 am
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.

Re: Send email using a macro

PostPosted: Wed Jul 04, 2018 12:05 pm
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.