OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Send an email from the API

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Gonzalo
Power User
Power User


Joined: 13 Apr 2004
Posts: 56

PostPosted: Fri Apr 23, 2004 5:34 am    Post subject: Send an email from the API Reply with quote

Hi, i would like to make a macro to send an email. I want the macro to open the mail client and send the mail. I'm using this code but this doesn't work at all. It can't create the SystemSimpleMail Service. If i use SimpleCommandMail i recieve a run time error too. Any idea? Thanks

' Example of how to send e-mail from Basic in OpenOffice.org.

Sub Main
' Your e-mail address goes here...
cEMailAddress = "me@somewhere.com"
cSubject = "Get generic Viagra online!!!"


' Use one of the following two lines, depending on which
' mailer you want to use.
' SimpleCommandMail will use your system's command line tools to send mail.
' SimpleSystemMail will use whatever (GUI) mail client you configured in
' Tools -> Options -> OpenOffice.org -> External Programs.
' For some reason the command line mail service does not appear to work on Windows?
'
' oMailer = createUnoService( "com.sun.star.system.SimpleCommandMail" )
oMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )


oMailClient = oMailer.querySimpleMailClient()

oMessage = oMailClient.createSimpleMailMessage()

oMessage.setRecipient( cEMailAddress )
oMessage.setSubject( cSubject )
'oMessage.setAttachment( .... )
' ...etc.

' The zero is the DEFAULTS constant from
' com.sun.star.system.SimpleMailClientFlags.
oMailClient.sendSimpleMailMessage( oMessage, o )
' One of the options in the SimpleMailClientFlags is an option
' to send the mail with no user interface. Just send it.
End Sub
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Fri Apr 23, 2004 6:11 am    Post subject: Reply with quote

Try this:

Code:

Sub SendEmail()
Dim eMailSystem
Dim omsg

eMailSystem=createUnoService( "com.sun.star.system.SimpleSystemMail" )
oMail = eMailSystem.querySimpleMailClient()
omsg = oMail.createsimplemailmessage()
With omsg
  .setsubject("MySubject")
  .setrecipient("dev@api.openoffice.org")' any adress
End With
oMail.sendSimpleMailMessage(omsg, com.sun.star.system.SimpleMailClientFlags.DEFAULTS)

End Sub 

_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
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
Page 1 of 1

 
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