Libreoffice Calc Macro not automatically send Email

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Kenneth08
Posts: 12
Joined: Fri Aug 25, 2017 4:02 am

Libreoffice Calc Macro not automatically send Email

Post by Kenneth08 »

Good day to all!

I have previous topic which entitled "How to send Email in Evolution mail using Calc Macro" (link:http://ooo-forums.apache.org/en/forum/v ... =9&t=90100)
However, my problem now is that my code is working but not sending automatically.
It just create an email and waiting for manual clicking of "Send button"

I am using Evolution as Mail application. Unfortunately, this is the required application on my work.
Below is my codes that create mail but not sending automatically.
Hope you can help me to revise my code to send my message without showing my current configured system mail client

Code: Select all

Sub SendMailPlease
eMailAddress = "**********@****.com"

   eSubject = "Test email"
   
   Sheet = ThisComponent.Sheets.getByName("Macro")
   Cell = Sheet.getCellrangeByName("H3")
   eBody = "Sample"

   eMailer = createUnoService("com.sun.star.system.SimpleCommandMail")
   eMailClient = eMailer.querySimpleMailClient()
   eMessage = eMailClient.createSimpleMailMessage()
   eMessage.Recipient = eMailAddress
   eMessage.Subject = eSubject
   eMessage.Body = eBody
   'AttachmentURL = convertToUrl("")
   'eMessage.Attachement = Array(AttachmentURL)
   eMailClient.sendSimpleMailMessage ( eMessage,com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE)
End Sub
Ubuntu 15.04
LibreOffice 4.4.2.2
Evolution 3.12.11
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Help! Libreoffice Calc Macro not automatically send Emai

Post by Zizi64 »

Has the Evolution such "silent mode" option? Can you try it from an another application or some another programming environment?
Do you know anything of the API of the Evolution?

https://developer.gnome.org/evolution-m ... .html#idxC

(I never used the Evolution)
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: Help! Libreoffice Calc Macro not automatically send Emai

Post by Villeroy »

You are not limited to Basic. Python is a fully functional programming language with a bridge to LibreOffice. You can write macros and office components in Python. You can write stand alone Python programs that communicate with a running office suite. With Python it is easy to send mail independently from any office suite.


The following demo script sends a simple text mail.
Save with .py suffix, make it executable, adjust the SMTP-settings and the mail message.

Code: Select all

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import smtplib
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart

########### SMTP-Settings ##############################
SMTP = "securesmtp.example.com"
SMTPport = 587
Sender = "myself@example.com"
User = Sender # or whatever log-in name
Passwort = "secret"
########################################################
########### Mail Message ###############################
addr = "receipient@example.com"
subj = "smtp test"
body = "Test. Check. One, Two. One, Two"
########################################################

# connect
server = smtplib.SMTP(SMTP, SMTPport)
server.ehlo()
server.starttls()
server.ehlo()
# log in
server.login(User, Passwort)

# construct mail
mail = MIMEText(body)
mail['From'] = Sender
mail['Subject'] = subj
mail['To'] = addr

# send
server.sendmail(Sender, addr, mail.as_string())    

# log off
server.quit()
Avoid any leading white space in this script. Leading white space has a meaning in Python.
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
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Libreoffice Calc Macro not automatically send Email

Post by Villeroy »

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