Sending an email from Calc with a macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Haese005
Posts: 4
Joined: Wed Mar 22, 2017 7:02 pm

Sending an email from Calc with a macro

Post by Haese005 »

Hi there,
Maybe I haven't searched enough in the database of this forum, but my problem is that I am looking for a simple macro script to send an email to 2 different email addresses from calc (see the attachment) .
My email client is Microsoft Outlook. My OpenOffice version is 4.1.3.
I must be able to put the subject in the email. That's all but I am an so called aliën in OpenOffice.
Can someone help me with this , please? ;)
Attachments
DAGREGISTRATIE SNEL SCHOON ZUID-OOST NIEUWE STIJL 2.0.ods
I am from the Netherlands so that's why the language in this spreadsheet is probably strange for you
(16 KiB) Downloaded 216 times
OpenOffice 4.13 and Operating system: Windows 10
Email Client: Outlook
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: sending an email from calc with a macro

Post by FJCC »

This works for me

Code: Select all

Sub SendEmail
eMailAddress = "dummy1@gmail.com; dummy2@gmail.com"
eSubject = "Test Message"
eMailer = createUnoService("com.sun.star.system.SystemMailProvider")

eMailClient = eMailer.queryMailClient()

eMessage = eMailClient.createMailMessage()

eMessage.Recipient = eMailAddress 
eMessage.Subject = eSubject
eMessage.Body = "The text in the message" 
AttachmentURL = convertToUrl("c:\users\fjcc\desktop\99Export.txt")
eMessage.Attachement = array(AttachmentURL)
eMailClient.sendMailMessage ( eMessage, com.sun.star.system.MailClientFlags.NO_USER_INTERFACE )
End Sub
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: sending an email from calc with a macro

Post by Zizi64 »

Code: Select all

eMailClient.sendMailMessage ( eMessage, com.sun.star.system.MailClientFlags.NO_USER_INTERFACE )
or when you want to control the mail client manually:

Code: Select all

eMailClient.sendSimpleMailMessage( eMessage, 0 )
My email client is Microsoft Outlook.
Try the ThunderBird e-mail client. It works well for me with similar macro codes.
(And it worked with the old OutlookExpress. I never used the MS Outlook...)
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.
Post Reply