Sending Mail from Calc Macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
JyotirmoyD
Posts: 2
Joined: Mon May 25, 2015 9:35 am

Sending Mail from Calc Macro

Post by JyotirmoyD »

I am trying to send mail directly from Calc.
I am using the below code (got this code from Oo forum)
Code is working fine when cell "H3" contains English Text. But when I am trying to send other language (Bengali in my case) receiver is getting ????? (question marks) in his mail box.
How to solve that issue.

Code: Select all

REM  *****  BASIC  *****

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

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

   eMailer = createUnoService("com.sun.star.system.SystemMailProvider")
   eMailClient = eMailer.queryMailClient()
   eMessage = eMailClient.createMailMessage()
   eMessage.Recipient = eMailAddress
   eMessage.Subject = eSubject
   eMessage.Body = eBody
   'AttachmentURL = convertToUrl("")
   'eMessage.Attachement = Array(AttachmentURL)
   eMailClient.sendMailMessage ( eMessage, com.sun.star.system.MailClientFlags.NO_USER_INTERFACE )
End Sub
Open Office 4.1.1 on Vista Business
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Sending Mail from Calc Macro

Post by Villeroy »

In the 90ies StarOffice had its own mail client. This decades old service may not support unicode.
LibreOffice seems to have modernized these services. At least they are renamed and modified somehow.
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
JyotirmoyD
Posts: 2
Joined: Mon May 25, 2015 9:35 am

Re: Sending Mail from Calc Macro

Post by JyotirmoyD »

Is there any way that I can send mail containing Other Languages from Calc using macro ?
Open Office 4.1.1 on Vista Business
User avatar
karolus
Volunteer
Posts: 1159
Joined: Sat Jul 02, 2011 9:47 am

Re: Sending Mail from Calc Macro

Post by karolus »

JyotirmoyD wrote:Is there any way that I can send mail containing Other Languages from Calc using macro ?
Of course -- but not with poor old basic

with Libreoffice4.4 (python3.3):

Code: Select all

from smtplib import SMTP
from email.mime.text import MIMEText
loginname = '....'
password = '....'
server = 'mail.some_provider.org'
me = 'my_name@some_provider.org'
subject = 'test germän umlauts'

def sendmail(*_):
    doc = XSCRIPTCONTEXT.getDocument()
    sel = doc.CurrentSelection
    msg = sel.String
    print( msg )
    # prints:
    # `hallölele {}` 
    message = MIMEText(msg.format(me ))
    message['Subject'] = subject
    message['From'] = me
    message['To'] = me

    with SMTP(server) as mailserver:
        mailserver.login(loginname, password)
        mailserver.send_message(message )
 
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Post Reply