You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

joekaisaka

Beginner

  • "joekaisaka" started this thread

Posts: 11

Date of registration: Feb 1st 2011

  • Send private message

1

Tuesday, March 15th 2011, 4:53pm

Outlook On Jabaco Using JACOB

Hi everybody:

I'm new in Jabaco and I don't programming in Java. Sorry for any inconvenience.

I found this code in java that send emails by outlook using JACOB. But I don't know how can I convert some parts:

Code found in : http://www.guj.com.br/java/100403-outloo…lvido-com-jacob


ActiveXComponent axcOutlook = new ActiveXComponent("Outlook.Application");
Dispatch criacaoEmail =
Dispatch.invoke(axcOutlook.getObject(), "CreateItem", Dispatch.Get,
new Object[] { "0" }, new int[0]).toDispatch();

String destinatario = "dpostatni@gmail.com";
String assunto = "Teste Jacob";
String corpoMensagem = "Teste JACOB com anexo";
Object anexo1 = new Object();
Object anexo2 = new Object();
anexo1 = "C:/Teste1.txt";
anexo2 = "C:/Teste2.txt";

Dispatch.put(criacaoEmail, "To", destinatario);
Dispatch.put(criacaoEmail, "Subject", assunto);

Dispatch.put(criacaoEmail, "Body", corpoMensagem);
Dispatch.put(criacaoEmail, "ReadReceiptRequested", "false");

Dispatch attachs = Dispatch.get(criacaoEmail, "Attachments").toDispatch();
Dispatch.call(attachs, "Add", anexo1);
Dispatch.call(attachs, "Add", anexo2);
Dispatch.call(criacaoEmail, "Display");


Thanks in Advance and sorry my poor english
Joe Kaisaka

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Tuesday, March 15th 2011, 5:11pm

This code snippet is using Outlook as ActiveX control. This is not directly feasible in Jabaco.
Jabaco does not offer direct support for ActiveX.
JACOB (= Java COM Bridge) can be linked into Jabaco programs.
Use the search facility of this forum to find a JACOB/Jabaco sample.

Another option would be to use a Java-based mailing framework.

Please post your findings!

A1880

joekaisaka

Beginner

  • "joekaisaka" started this thread

Posts: 11

Date of registration: Feb 1st 2011

  • Send private message

3

Tuesday, March 15th 2011, 6:19pm

A1880:

Thanks for your reply. You are a very active member of this community and I'm happy because you read and answer my single post.

I know the code that I post is java + jacob and jabaco doesn't offer direct support of ActiveX. But reading the great post of Stefan Schnell [How to use JavaCOMBridge (JaCoB) with Microsoft Word] I was thinking to try convert the code, but I don't know how can I convert some parts of code (red painted).

I need send emails using outlook and I think to make this in jabaco to learn more about this powerful tool.

Thanks in Advance

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

4

Wednesday, March 16th 2011, 9:02am

As far as I know, the red snippets cannot be migrated to Jabaco.
The reason is that Jabaco does not support passing Java arrays as parameters when calling a method.

One could write the code in question in Java, export it into a Jar file and import this into the Jabaco project.

To simply send mails from a Jabaco application, you could use an external tool like blat
Using the "Interaction.Shell()" method, such external tools can be started as subprocess of your application.

Have fun!

A1880

joekaisaka

Beginner

  • "joekaisaka" started this thread

Posts: 11

Date of registration: Feb 1st 2011

  • Send private message

5

Thursday, March 17th 2011, 11:58am

My Friends :

I made this. This code works for me.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Public Sub JSendEmailFromOutlook( cTo As String, cSubject As String, cBody As String, Optional arrAttachments() As String, Optional lReadReceiptConfirmation As Boolean = False)
Dim oOutlook As com#jacob#activeX#ActiveXComponent 
Dim oOL As com#jacob#com#Dispatch 
Dim oNs As com#jacob#com#Dispatch
Dim oMail As com#jacob#com#Dispatch
Dim oAttachs As com#jacob#com#Dispatch
Dim mapi(0)As Object
Dim email(0) As Object
Dim nAttach As Integer
Dim attachment(0) As Object

mapi(0) = "MAPI"
email(0) = 0
Set oOutlook = New ActiveXComponent("Outlook.Application")
oOL = oOutlook.getObject()
oNs = com#jacob#com#Dispatch.call(oOL,"GetNamespace",mapi).toDispatch
oMail = com#jacob#com#Dispatch.call(oOutlook,"CreateItem",email).toDispatch

com#jacob#com#Dispatch.put(oMail, "To", cTo) 
com#jacob#com#Dispatch.put(oMail, "Subject", cSubject) 
com#jacob#com#Dispatch.put(oMail, "Body", cBody) 
com#jacob#com#Dispatch.put(oMail, "ReadReceiptRequested", lReadReceiptConfirmation)

If Ubound(arrAttachments) > 0 Then
	oAttachs = com#jacob#com#Dispatch.get(oMail, "Attachments").toDispatch() 
	For nAttach = 0 To Ubound(arrAttachments) 
		 attachment(0) = arrAttachments(nAttach) 
		 com#jacob#com#Dispatch.call(oAttachs, "Add", attachment)
	Next nAttach
End If 

com#jacob#com#Dispatch.call(oMail, "Send")

End Sub


Thanks for the patience.


PS : Tested only Outlook 2010. I will make tests in others Outlook Versions

This post has been edited 1 times, last edit by "joekaisaka" (Mar 17th 2011, 12:17pm)


joekaisaka

Beginner

  • "joekaisaka" started this thread

Posts: 11

Date of registration: Feb 1st 2011

  • Send private message

6

Thursday, March 17th 2011, 3:03pm

Hi Folks:

I made some changes and fix some bugs. Hope you enjoy.

New features:

- CC propery
- BCC property
- Importance property
- Close Outlook after the mail is sent

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Public Sub JSendEmailFromOutlook( cTo As String, Optional cSubject As String = "", Optional cBody As String = "", Optional cCC As String = "", Optional cBCC As String = "", Optional arrAttachments() As String, Optional lReadReceiptConfirmation As Boolean = False, Optional nImportance As Integer = 0)

Dim oOutlook As com#jacob#activeX#ActiveXComponent 
Dim oOL As com#jacob#com#Dispatch 
Dim oNs As com#jacob#com#Dispatch
Dim oMail As com#jacob#com#Dispatch
Dim oAttachs As com#jacob#com#Dispatch
Dim mapi(0)As Object
Dim email(0) As Object
Dim nAttach As Integer
Dim attachment(0) As Object

mapi(0) = "MAPI"
email(0) = 0

Set oOutlook = New ActiveXComponent("Outlook.Application")
oOL = oOutlook.getObject()
oNs = com#jacob#com#Dispatch.call(oOL,"GetNamespace",mapi).toDispatch
oMail = com#jacob#com#Dispatch.call(oOutlook,"CreateItem",email).toDispatch

com#jacob#com#Dispatch.put(oMail, "To", cTo) 
com#jacob#com#Dispatch.put(oMail, "Subject", cSubject) 

If Len(Trim(cCC)) > 0 Then
      com#jacob#com#Dispatch.put(oMail, "CC", cCC)
End If      

If Len(Trim(cBCC)) > 0 Then
      com#jacob#com#Dispatch.put(oMail, "BCC", cBCC)
End If      
       
com#jacob#com#Dispatch.put(oMail, "Body", cBody) 
com#jacob#com#Dispatch.put(oMail, "ReadReceiptRequested", lReadReceiptConfirmation)
com#jacob#com#Dispatch.put(oMail, "Importance", nImportance) 

If Ubound(arrAttachments) > 0 Then

   oAttachs = com#jacob#com#Dispatch.get(oMail, "Attachments").toDispatch() 
   
   For nAttach = 0 To Ubound(arrAttachments)
      attachment(0) = arrAttachments(nAttach)
      com#jacob#com#Dispatch.call(oAttachs, "Add", attachment)
   Next nAttach
   
End If   

com#jacob#com#Dispatch.call(oMail, "Send")
com#jacob#com#ComThread.Release
   
End Sub


I know I missing some cool things like error handling. Also have not tested the image in the message body. But did the best I could.
I thank you all.

Sorry the poor english,

Joe Kaisaka

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

7

Thursday, March 17th 2011, 3:05pm

Great!

I tried it with Outlook 2007. It worked without problems.

A slightly reformatted version which makes use of the import statement:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Option Explicit

Import com#jacob#activeX 
Import com#jacob#com 

Public Sub JSendEmailFromOutlook( cTo As String, cSubject As String, cBody As String, Optional arrAttachments() As String, Optional lReadReceiptConfirmation As Boolean = False)
   Dim oOutlook As ActiveXComponent 
   Dim oOL As Dispatch 
   Dim oNs As Dispatch
   Dim oMail As Dispatch
   Dim oAttachs As Dispatch
   Dim mapi(0)As Object
   Dim email(0) As Object
   Dim nAttach As Integer
   Dim attachment(0) As Object

   mapi(0) = "MAPI"
   email(0) = 0
   Set oOutlook = New ActiveXComponent("Outlook.Application")
   oOL = oOutlook.getObject()
   oNs = Dispatch.call(oOL,"GetNamespace",mapi).toDispatch
   oMail = Dispatch.call(oOutlook,"CreateItem",email).toDispatch

   Dispatch.put(oMail, "To", cTo) 
   Dispatch.put(oMail, "Subject", cSubject) 
   Dispatch.put(oMail, "Body", cBody) 
   Dispatch.put(oMail, "ReadReceiptRequested", lReadReceiptConfirmation)

   If Ubound(arrAttachments) > 0 Then
      oAttachs = Dispatch.get(oMail, "Attachments").toDispatch() 
      For nAttach = 0 To Ubound(arrAttachments) 
          attachment(0) = arrAttachments(nAttach) 
          Dispatch.call(oAttachs, "Add", attachment)
      Next nAttach
   End If 

   Dispatch.call(oMail, "Send")

End Sub

Public Sub Command1_Click()
   JSendEmailFromOutlook "xyz@myDomain.org", "Test", "a small" & vbCrLf & "Test"
End Sub


As soon as the project is actually saved in a project directory, the Jacob native dll has to be on the library search path.
I've put it into the project directory.

I was wrong assuming that Jabaco could not pass genuine Java arrays when calling a method.
Arrays of Objects are properly passed.
I tried arrays of char without success.

Greetings!

A1880

Posts: 5

Date of registration: Nov 21st 2012

  • Send private message

8

Tuesday, December 4th 2012, 10:16am

Active X component

Hi,

Would appreciate your assistance, if I run the project I get the following error:

Class Active X Component not found. Please assist, I did add the jacob.dll & the ActiveXComponent.class...

I don't know where I am going wrong.

Kind Regards,
Elsebi

Posts: 5

Date of registration: Nov 21st 2012

  • Send private message

9

Wednesday, December 5th 2012, 7:31am

Hi,

So I got the program to run finally :) but it isn't doing anything...please assist. Its not sending any e-mail...please assist. Will be much appreciated.

Kind Regards,
Elsebi

joekaisaka

Beginner

  • "joekaisaka" started this thread

Posts: 11

Date of registration: Feb 1st 2011

  • Send private message

10

Thursday, December 6th 2012, 12:18pm

Hi Elsebi

There are many time that I don't develop with JABACO. ;( There's no special reason.
I don't remember which dll I setted in my code. :( :(
And this moment I don't have Outlook installed in my computer :(
I`ll search the project. If I found, I`ll send for you. :thumbsup:


Sorry my very very poor english.

joekaisaka

Beginner

  • "joekaisaka" started this thread

Posts: 11

Date of registration: Feb 1st 2011

  • Send private message

11

Thursday, December 6th 2012, 1:08pm

Elsebi :

I remember something now:

1) Are JACOB DLLs in \Program Files (x86)\Java\jre6\bin ?
2) I'm not sure about this, but I think jacob.jar are C:\Program Files (x86)\Java\jre6\lib OR C:\Program Files (x86)\Java\jre6\lib\ext OR C:\Program Files\Java\jdk1.X.X_XX\lib\ext (yes, to try this option, you'll need install JDK in your PC)

Best Regards

Posts: 5

Date of registration: Nov 21st 2012

  • Send private message

12

Thursday, December 6th 2012, 2:53pm

Hi Joelaisaka,

Thank you very much I got it to work!

with the 86.dll

Have a good day
Elsebi

Rate this thread
WoltLab Burning Board