Libreoffice Calc Macro not automatically send Email

Creating a macro - Writing a Script - Using the API

Libreoffice Calc Macro not automatically send Email

Postby Kenneth08 » Thu Aug 31, 2017 3:54 am

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/viewtopic.php?f=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   Expand viewCollapse view
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
Kenneth08
 
Posts: 12
Joined: Fri Aug 25, 2017 4:02 am

Re: Help! Libreoffice Calc Macro not automatically send Emai

Postby Zizi64 » Thu Aug 31, 2017 7:03 am

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; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.5; AOO4.1.6
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: 8319
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Help! Libreoffice Calc Macro not automatically send Emai

Postby Villeroy » Thu Aug 31, 2017 9:36 am

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   Expand viewCollapse view
#!/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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27200
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Libreoffice Calc Macro not automatically send Email

Postby Villeroy » Sat Sep 09, 2017 5:41 pm

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: 27200
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 4 guests