Where  can I find parameters of objects, services in Basic? For example I have Service: com.sun.star.system.SimpleSystemMail. I know I can use ".setRecipient" , ".setSubject". But where can I find full list of all parameters? On this page I could find only some descriptions:
http://www.openoffice.org/api/docs/comm ... mMail.html
Sorry for noob question. Thank you for help
Title Edited. A descriptive title for posts helps others who are searching for solutions and increases the chances of a reply (Hagar, Moderator).
			
			
									
						
							How to get parameters of objects, services?
How to get parameters of objects, services?
OpenOffice 3.4
			
						Re: Beginner question...
Hello
You need also this interface.
http://www.openoffice.org/api/docs/comm ... ssage.html
I think it is exported by the service you have.
For an example of how to use see this thread.
http://forum.openoffice.org/en/forum/vi ... 2&p=199314
Romke
			
			
									
						
							You need also this interface.
http://www.openoffice.org/api/docs/comm ... ssage.html
I think it is exported by the service you have.
For an example of how to use see this thread.
http://forum.openoffice.org/en/forum/vi ... 2&p=199314
Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
			
						Re: How to get parameters of objects, services?
Thank you for answer that helped me a lot.
Last question: How it is possible that there is no parameter to set email content? I think parameter to set message is most important one.
			
			
									
						
							Last question: How it is possible that there is no parameter to set email content? I think parameter to set message is most important one.
OpenOffice 3.4
			
						Re: How to get parameters of objects, services?
Hello
On this moment I have no time for testing. I do also not know the answers but maybe you need the method of setSubject. When I have time I wil try to test it.
Romke
			
			
									
						
							On this moment I have no time for testing. I do also not know the answers but maybe you need the method of setSubject. When I have time I wil try to test it.
Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
			
						Re: How to get parameters of objects, services?
Hi 
Thank you. Method setSubject is only for Subject of email. It should be also method like "setMessage" . Maybe I should use another UnoService
			
			
									
						
							Thank you. Method setSubject is only for Subject of email. It should be also method like "setMessage" . Maybe I should use another UnoService
OpenOffice 3.4
			
						Re: How to get parameters of objects, services?
Hello
I have tried to send an email with OOo. I'm not succeed in a way I want now. I'm not sure if it is possible.I have searched on the old forum and did find there a thread. Linking to that thread is not useful there the old forum is most of the time now offline. For that reason I do place here the text as code. The text is not cleaned up but possible it is useful for you.
Romke
			
			
									
						
							I have tried to send an email with OOo. I'm not succeed in a way I want now. I'm not sure if it is possible.I have searched on the old forum and did find there a thread. Linking to that thread is not useful there the old forum is most of the time now offline. For that reason I do place here the text as code. The text is not cleaned up but possible it is useful for you.
Romke
Code: Select all
module com.sun.star.mail
Author 	Message
Peter
OOo Enthusiast
OOo Enthusiast
Joined: 28 May 2004
Posts: 105
Location: Berlin / Germany
	
PostPosted: Fri Jan 06, 2006 6:37 am    
Hi,
Caolan offered with 2.0.1 the possibility to mailmerge with email (/program/mailmerge.py).
I would like to use the subject module for mailing in some cases.
I know the css.system.SimpleSystemMail service, but it has some restrictions (no access to body, standard mailhandler required).
Has anybody played with this?
I can use the service com.sun.star.mail.MailserviceProvider, but for that I need the context for the server settings...
I can't get the service com.sun.star.mail.Mailserver (null-object), where I can provide these server settings
Sad
Is the JavaMail api required here?
Sincerely
Peter
ms777
Super User
Super User
Joined: 07 Feb 2004
Posts: 1354
	
Hi,
I have played around a bit with the mail API in 2.0.1 on Win XP, but to no success. In the code below, all the objects are created, and I beleive that the provider is even accessed. At the end, however, a strange error (mailmerge.py expecting 2 parameters but got 3) arises ... maybe you are more successful Smile
Good luck,
ms777
Code:	
Sub Main
oMSP = createUnoService("com.sun.star.mail.MailServiceProvider")
'xray oMSP
oMS = oMSP.create(com.sun.star.mail.MailServiceType.POP3)
'xray oMS
oCurCont = CreateUnoListener("CurCont_", "com.sun.star.uno.XCurrentContext")
oAuthent = CreateUnoListener("Authent_", "com.sun.star.mail.XAuthenticator")
'xray oCurCont
'xray oAuthent
oMS.connect(oCurCont, oAuthent)
xray oMS
End Sub
function CurCont_getValueByName(s as String) as Any
select case LCase(s)
  case "servername"
    CurCont_getValueByName = "pop3.web.de"
  case "port"
    CurCont_getValueByName = CLng(110)
  case "connectiontype"
    CurCont_getValueByName = "ssl"
  end select
end function
function Authent_getUserName() as String
Authent_getUserName = "myUserName_changeme"
end function
function Authent_getPassword() as String
Authent_getPassword = "myPassword_changeme"
end function	
Back to top 	
View user's profile Send private message 	 	
Peter
OOo Enthusiast
OOo Enthusiast
Joined: 28 May 2004
Posts: 105
Location: Berlin / Germany
	
PostPosted: Fri Jan 20, 2006 8:52 am    Post subject: 	Reply with quote
Thanks for the hint with the listeners and the callback functions, where did you found that stuff?
Yes, I can connect to the SMTP-server and will try to send a mail in a next step.
Pop with ssl: Isn't it port 995 ?
Peter
Back to top 	
View user's profile Send private message 	 	
Peter
OOo Enthusiast
OOo Enthusiast
Joined: 28 May 2004
Posts: 105
Location: Berlin / Germany
	
PostPosted: Thu Jan 26, 2006 4:24 am    Post subject: 	Reply with quote
Here's the code for connecting to SMTP:
oMailProvider = CreateUNOService("com.sun.star.mail.MailServiceProvider")
oCont = CreateUNOListener("CurCont_","com.sun.star.uno.XCurrentContext")
oAuth = CreateUNOListener("Authent_","com.sun.star.mail.XAuthenticator")
xMailServer = oMailProvider.Create("com.sun.star.mail.SMTP")
xMailServer.Connect(oCont,oAuth)
msgbox xMailServer.isConnected
XRay xMailServer
xMailServer.Disconnect()
'the message can be sent with xMailserver.sendMailMessage(xMailMessage) but I found no way to instanciate a com.sun.star.mail.MailMessage
Function CurCont_GetValueByName(s) as Any
Select Case s
Case "ServerName"
CurCont_GetValueByName = "MyMailServer"
Case "Port"
CurCont_GetValueByName = 25
Case "ConnectionType"
CurCont_GetValueByName = "Insecure"
End Select
End Function
Function Authent_GetUserName() as Any
Authent_GetUserName = ""
End Function
Function Authent_GetPassword()
Authent_GetPassword = ""
End Function
Back to top 	
View user's profile Send private message 	 	
-Manu_
Newbie
Newbie
Joined: 28 May 2006
Posts: 2
	
PostPosted: Sun May 28, 2006 7:50 am    Post subject: sending mail 	Reply with quote
this is very intersting,
but when i didn't succed in sending mail.
When you said "'the message can be sent with xMailserver.sendMailMessage(xMailMessage) but I found no way to instanciate a com.sun.star.mail.MailMessage "
Does is it mean that you are in the same case ?
How can you creat a xMailMessage ?
Thanks
Emmanuel
Back to top 	
View user's profile Send private message 	 	
Peter
OOo Enthusiast
OOo Enthusiast
Joined: 28 May 2004
Posts: 105
Location: Berlin / Germany
	
PostPosted: Sun May 28, 2006 10:34 pm    Post subject: Re: sending mail 	Reply with quote
-Manu_ wrote:	
How can you creat a xMailMessage ?
Nope, I can't. That's the problem.
I think it can't be done in BASIC.
Caolan did it in the python mailmerge script, so I'm hoping an experienced python programmer can finish this task. And the python script could be invoked by a BASIC routine.
Peter
Back to top 	
View user's profile Send private message 	 	
-Manu_
Newbie
Newbie
Joined: 28 May 2006
Posts: 2
	
PostPosted: Wed May 31, 2006 11:34 am    Post subject: sending mail 	Reply with quote
hi,
just a question :
why this :
MonMsg=CreateUnoService("com.sun.star.mail.MailMessage")
MonMsg.Create("from@mail.com", "to@maill.com", "subject", "msg")
doesn't work ? (or shouldn't work)
Manu
PS :i'm not an expert of openoffice basic api!
Back to top 	
View user's profile Send private message 	 	
andreasm
Power User
Power User
Joined: 06 Dec 2003
Posts: 54
Location: South Tyrol
	
PostPosted: Sun May 24, 2009 10:53 am    Post subject: 	Reply with quote
Hello,
I know this is a old thread, but I would like to use the mailing functions of openoffice.
I tried the code posted by Peter but I got an exception.
I looked at
http://api.openoffice.org/docs/common/ref/com/sun/star/mail/XMailServer.html#Name
and I think there are some attributes missing.
Nowhere in the code the destination smtp server is set !
According to the documentation the name and port attributes must be set.
Can anyone tell how to set attributes in ooobasic ?
I tried with
xMailserver.name="mail.gmx.net"
rem xMailserver.port=25
but this does not work
Bye
Andreas
Back to top 	
View user's profile Send private message 	 	
hol.sten
Super User
Super User
Joined: 14 Nov 2004
Posts: 3529
Location: Hamburg, Germany
	
PostPosted: Sun May 24, 2009 12:20 pm    Post subject: 	Reply with quote
All I can provide is a working script in Java: [Java] Send an email from an OOo Writer document: http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=3813
Back to top 	
View user's profile Send private message 	 	
Peter
OOo Enthusiast
OOo Enthusiast
Joined: 28 May 2004
Posts: 105
Location: Berlin / Germany
	
PostPosted: Sun May 24, 2009 11:34 pm    Post subject: 	Reply with quote
andreasm wrote:	
Nowhere in the code the destination smtp server is set !
According to the documentation the name and port attributes must be set.
Take a look at the function CurCont_GetValueByName() and you will find the server name and port.
Peter
Back to top 	
View user's profile Send private message 	 	
andreasm
Power User
Power User
Joined: 06 Dec 2003
Posts: 54
Location: South Tyrol
	
PostPosted: Tue May 04, 2010 11:17 pm    Post subject: 	Reply with quote
Hello,
maybe I am wrong, but I studied Caolan's python source and IMHO he does not only use the sendmail function, he implemented it in python !
I added this lines to Peter's basic code ( above )
oMail = CreateUNOListener("Mail_","com.sun.star.mail.XMailMessage")
and after the connect
xMailServer.SendMailMessage(oMail)
and this callback functions:
function Mail_SenderAddress()
Msgbox ("Sender")
Mail_SenderAddress="sender@test.net"
end function
function Mail_GetRecipients()
msgbox("Recipients")
Mail_GetRecipients="recipient@test.net"
end function
GetRecipient IS called, but I get a conversion error, because a array( or somethin similar ) is expected as return value.
Does someone know how to return the expected data ?
Bye
Andreas
Back to top 	
View user's profile Send private message 	 	
Peter
OOo Enthusiast
OOo Enthusiast
Joined: 28 May 2004
Posts: 105
Location: Berlin / Germany
	
PostPosted: Wed May 05, 2010 1:08 am    Post subject: 	Reply with quote
Did you try Mail_GetRecipients=Array("recipient@test.net") ?
Peter
Back to top 	
View user's profile Send private message 	 	
andreasm
Power User
Power User
Joined: 06 Dec 2003
Posts: 54
Location: South Tyrol
	
PostPosted: Thu May 06, 2010 12:11 am    Post subject: 	Reply with quote
Hello,
no, Now there is another error
type coercion failed: TYPE is not supported
Bye
Andreas
Back to top 	
View user's profile Send private message 	 	
andreasm
Power User
Power User
Joined: 06 Dec 2003
Posts: 54
Location: South Tyrol
	
PostPosted: Fri May 14, 2010 11:32 pm    Post subject: 	Reply with quote
Hello,
thanks to Caolan we are near to a solution
http://qa.openoffice.org/issues/show_bug.cgi?id=111508
What I miss now is a way to send a attachment.I tried with
oMail = oMailServiceObj.createWithAttachment()
but I have to create a com:sun:star:mail:MailAttachment out of a file and don't know how to do it.
Bye
Andreas
Back to top 	
View user's profile Send private message 	 	
DonJaime
Newbie
Newbie
Joined: 05 Jan 2012
Posts: 2
	
PostPosted: Thu Jan 05, 2012 3:15 pm   
With the python fix it is now possible to create and send a message with a body. None of the 'add' methods of XMailMessage work (they all cause an error when sending the message). And it is still completely obscure how an attachment is meant to be created from a file: (whining went here).
Edit next day:
Quit whinging and solved the attachment problem: the documentation for com.sun.star.mail.MailAttachment says that the attachment data should be provided as a "sequence of bytes", but in fact what is required is a byte sequence. Which can be created from a sequence (Array) of bytes as returned by the com.sun.star.ucb.SimpleFileAccess service's readBytes() function by using the CreateUnoValue() function. So here is how I send an email with a body and an attachment from OpenOffice.org/LibreOffice:
Code:	
Option Explicit
' ======= just for testing =======
const testRecipient = "you@example.com"
sub Testmail
   smtpPassword = inputBox("Password", "Password:", "")
   attachmentType = "application/pdf"
   sendMail(testRecipient, "Attachment", "Test the first", _
      ConvertToUrl("c:\Documents and Settings\James\Desktop\test.pdf"))
   sendMail(testRecipient, "No attachment", "Test the second")
end sub
' ======== your details go here ========
const myAddress = "you@example.com"
const smtpServer = "mail.example.com"
const smtpPort = 25
const smtpSecure = true
const smtpUser = "you@example.com"
const attachmentMaxSize = 100000
' these variables are needed by listener functions, to which they cannot be passed as arguments
private smtpPassword as String
private messageBody as String
private attachmentContents as Object
private attachmentType as String
sub sendMail(recipient, subject, body, Optional attachmentUrl)
dim bodyObject as Object, attachment as Object, message as Object, _
   serviceProvider as Object, service as Object, server as Object, mailUser as Object
   bodyObject = CreateUNOListener("body_", "com.sun.star.datatransfer.XTransferable")
   messageBody = body
   if not IsMissing(attachmentUrl) then _
      if attachmentFromUrl(attachment, attachmentUrl) <> "OK" then : exit sub
   end if
   
   message = com.sun.star.mail.MailMessage.createWithAttachment(_
      recipient, myAddress, subject, bodyObject, attachment)
   serviceProvider = CreateUNOService("com.sun.star.mail.MailServiceProvider")
   service = serviceProvider.Create("com.sun.star.mail.SMTP")
   server = CreateUNOListener("smtp_", "com.sun.star.uno.XCurrentContext")
   mailUser = CreateUNOListener("user_", "com.sun.star.mail.XAuthenticator")
   service.Connect(server, mailUser)
   service.SendMailMessage(message)
   service.Disconnect()
end sub
' ======= extract attachment data from file ========
function attachmentFromUrl(attachment, url)
dim chunks() as String, fileName as String, fileService as Object, _
   attachmentFile as Object, fileContents() as Byte
   
   chunks() = Split(url, "/")
   fileName = ConvertFromUrl(chunks(UBound(chunks()))
   fileService = createUnoService("com.sun.star.ucb.SimpleFileAccess")
   attachmentFile = fileService.OpenFileRead(url)
   attachmentFile.ReadBytes(fileContents(), attachmentMaxSize + 1)
   attachmentFile.CloseInput
   if (UBound(fileContents()) + 1 > attachmentMaxSize) then
      msgBox "Attachment file '" & fileName & "' is too big"
      exit function
   elseIf (UBound(fileContents()) < 0) then
      msgBox "Attachment file '" & fileName & "' is empty"
      exit function
   end if
   attachmentContents = CreateUnoValue( "[]byte", fileContents())
   attachment = CreateObject("com.sun.star.mail.MailAttachment")
   attachment.Data = CreateUNOListener("attachment_", "com.sun.star.datatransfer.XTransferable")
   attachment.ReadableName = fileName
   attachmentFromUrl = "OK"
end function
' ===== server properties =====
function smtp_GetValueByName(what)
   select case what
      case "ServerName"
         smtp_GetValueByName = smtpServer
      case "Port"
         smtp_GetValueByName = smtpPort
      case "ConnectionType"
         if smtpSecure then
            smtp_GetValueByName = "SSL"
         else
            smtp_GetValueByName = "Insecure"
         endif
   end select
end function
' ====== email user methods =======
function user_GetUserName()
   user_GetUserName = smtpUser
end function
function user_GetPassword()
   user_GetPassword = smtpPassword
end function
' ====== message body object methods ======
function body_GetTransferDataFlavors()
   dim flavor as new com.sun.star.datatransfer.DataFlavor
   flavor.MimeType = "text/plain;charset=utf-16"
   flavor.HumanPresentableName = "Unicode text"
   body_getTransferDataFlavors = Array(flavor)
end function
function body_GetTransferData(flavor) as any
   if (flavor.MimeType = "text/plain;charset=utf-16") then
      body_GetTransferData = messageBody
   end if
end function
function body_isDataFlavorSupported(x as Object)
   body_isDataFlavorSupported = (x.MimeType = "text/plain;charset=utf-16")
end function
' ====== attachment object methods ======
function attachment_GetTransferDataFlavors()
   dim flavor as new com.sun.star.datatransfer.DataFlavor
   flavor.MimeType = attachmentType
   flavor.HumanPresentableName = attachmentType
   attachment_getTransferDataFlavors = Array(flavor)
end function
function attachment_GetTransferData(flavor) as any
   if (flavor.MimeType = attachmentType) then
      attachment_GetTransferData = attachmentContents
   end if
end function
function attachment_isDataFlavorSupported(x as Object)
   attachment_isDataFlavorSupported = (x.MimeType = attachmentType)
end function
Back to top 	
View user's profile Send private message 	 	
Display posts from previous:   
Post new topic   Reply to topic 	   OOoForum.org Forum Index -> OpenOffice.org Macros and API 	All times are GMT - 8 Hours
Goto page 1, 2  Next
Page 1 of 2
 
	
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Powered by phpBB © 2001, 2005 phpBB Group
PostPosted: Tue Jan 17, 2012 4:40 am    Post subject: 	Reply with quote
DonJaime
i tested you code with the newest MergeMail.py from Ariel http://svn.apache.org/viewvc?view=revision&revision=1232130
Your code gives no errors but:
the email is comming in with the "sign" of a attachment, but affter opening the incomming email , there is no attchement.
same when using the "add.attachment" method.
I am using ThunderBirth with a IMAP acount .
Thanks for the work done
Fernand
ps: the add.recipient method is working now
Back to top 	
View user's profile Send private message Send e-mail 	 	
DonJaime
Newbie
Newbie
Joined: 05 Jan 2012
Posts: 2
	
PostPosted: Tue Jan 17, 2012 5:20 am    Post subject: 	Reply with quote
That sounds like the effect of Bug 118791 (https://issues.apache.org/ooo/show_bug.cgi?id=118791). Have a look at the message source and see if the "Content-Disposition" header of the attachment is garbled.
Back to top 	
View user's profile Send private message 	 	
Fernand
OOo Enthusiast
OOo Enthusiast
Joined: 22 Jun 2004
Posts: 142
	
PostPosted: Tue Jan 17, 2012 6:55 am    Post subject: 	Reply with quote
Yep,
the construct filename*="utf-8''nameooftefile
is not working with a kot of browsers
the solutioncould be to to deliver the filename as a URL
i suppose we can use converttoURL(path)
i contact Ariel by mail
Back to top 	
View user's profileLibreOffice 24.8.5.2 on openSUSE Leap 15.6