Page 1 of 1

Sending an email from Calc with a macro

Posted: Wed Mar 22, 2017 7:21 pm
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? ;)

Re: sending an email from calc with a macro

Posted: Wed Mar 22, 2017 8:49 pm
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

Re: sending an email from calc with a macro

Posted: Wed Mar 22, 2017 8:57 pm
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...)