Page 1 of 1

Libreoffice Calc Macro not automatically send Email

PostPosted: Thu Aug 31, 2017 3:54 am
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/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

Re: Help! Libreoffice Calc Macro not automatically send Emai

PostPosted: Thu Aug 31, 2017 7:03 am
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)

Re: Help! Libreoffice Calc Macro not automatically send Emai

PostPosted: Thu Aug 31, 2017 9:36 am
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   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.

Re: Libreoffice Calc Macro not automatically send Email

PostPosted: Sat Sep 09, 2017 5:41 pm
by Villeroy