Sending Mail from Calc Macro

Keyboard macros or custom scripts

Sending Mail from Calc Macro

Postby JyotirmoyD » Mon May 25, 2015 9:52 am

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   Expand viewCollapse view
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
JyotirmoyD
 
Posts: 2
Joined: Mon May 25, 2015 9:35 am

Re: Sending Mail from Calc Macro

Postby Villeroy » Mon May 25, 2015 1:51 pm

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, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 25958
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Sending Mail from Calc Macro

Postby JyotirmoyD » Tue May 26, 2015 6:03 am

Is there any way that I can send mail containing Other Languages from Calc using macro ?
Open Office 4.1.1 on Vista Business
JyotirmoyD
 
Posts: 2
Joined: Mon May 25, 2015 9:35 am

Re: Sending Mail from Calc Macro

Postby karolus » Tue May 26, 2015 3:35 pm

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   Expand viewCollapse view
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 - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 843
Joined: Sat Jul 02, 2011 9:47 am


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 4 guests