Jacob Com Outlook send mail using Dispatch.call
Hey all I am trying to send out an outlook email from Java using the JACOB COM activex code.
This is currently my code:
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import java.util.HashMap;
import java.util.Map;
public class MailOut implements com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
Map<String, Object> params = new HashMap<String, Object>();
String attachment = new String[1];
String to = new String[1];
public MailOut() {
}
public String exec(ITestExecutionServices tes, String args) {
//---------------------------------------------------------------------
params.put("subject", "Test subject");
params.put("body", "Please see attached.");
attachment[0] = "C:\temp\about_blank.pdf";
params.put("attachments", attachment);
to[0] = "me@here.com";
params.put("to", to);
OutlookJACOB mail = new OutlookJACOB();
mail.createEmail(params);
//---------------------------------------------------------------------
return "";
}
public class OutlookJACOB
{
private ActiveXComponent ol;
private Dispatch outlook;
private Object mapi = new Object[1];
private Object email = new Object[1];
public OutlookJACOB()
{
mapi[0] = "MAPI";
email[0] = 0;
ol = new ActiveXComponent("Outlook.Application");
//ol.setProperty("Visible", new Variant(true));
outlook = ol.getObject();
Dispatch.call(outlook,"GetNamespace",mapi).toDispatch();
}
public void createEmail(Map<String, Object> params)
{
Dispatch mail = Dispatch.call(outlook,"CreateItem",email).toDispatch();
Dispatch.put(mail, "Subject", params.get("subject"));
Dispatch.put(mail, "HTMLBody", params.get("body"));
String to = (String) params.get("to");
String attachments = (String) params.get("attachments");
if(to != null)
{
if(to.length>0)
{
String _to = "";
for(Object t : to)
{
_to += t + ";";
}
Dispatch.put(mail, "To", _to);
}
}
if(attachments != null)
{
if(attachments.length>0)
{
Dispatch attachs = Dispatch.get(mail, "Attachments").toDispatch();
for(Object attachment : attachments)
{
Dispatch.call(attachs, "Add", attachment);
}
}
}
//Dispatch.call(mail, "Send");
try {
Dispatch.call(mail, "Send");
} catch (com.jacob.com.ComFailException e) {
e.printStackTrace();
}
}
}
}
The line error is this line:
Dispatch.call(mail, "Send");
and the error states:
com.jacob.com.ComFailException:
A COM exception has been encountered:
At Invoke of: Send
Description: 80004004 / Operation aborted
Now I know my code is correct because if I do:
Dispatch.call(mail, "Save");
Then it does put that email I created into the Draft folder in Outlook:
So, what in the gobble gobble am I missing here in order to send it and not save it?
java eclipse outlook jacob
add a comment |
Hey all I am trying to send out an outlook email from Java using the JACOB COM activex code.
This is currently my code:
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import java.util.HashMap;
import java.util.Map;
public class MailOut implements com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
Map<String, Object> params = new HashMap<String, Object>();
String attachment = new String[1];
String to = new String[1];
public MailOut() {
}
public String exec(ITestExecutionServices tes, String args) {
//---------------------------------------------------------------------
params.put("subject", "Test subject");
params.put("body", "Please see attached.");
attachment[0] = "C:\temp\about_blank.pdf";
params.put("attachments", attachment);
to[0] = "me@here.com";
params.put("to", to);
OutlookJACOB mail = new OutlookJACOB();
mail.createEmail(params);
//---------------------------------------------------------------------
return "";
}
public class OutlookJACOB
{
private ActiveXComponent ol;
private Dispatch outlook;
private Object mapi = new Object[1];
private Object email = new Object[1];
public OutlookJACOB()
{
mapi[0] = "MAPI";
email[0] = 0;
ol = new ActiveXComponent("Outlook.Application");
//ol.setProperty("Visible", new Variant(true));
outlook = ol.getObject();
Dispatch.call(outlook,"GetNamespace",mapi).toDispatch();
}
public void createEmail(Map<String, Object> params)
{
Dispatch mail = Dispatch.call(outlook,"CreateItem",email).toDispatch();
Dispatch.put(mail, "Subject", params.get("subject"));
Dispatch.put(mail, "HTMLBody", params.get("body"));
String to = (String) params.get("to");
String attachments = (String) params.get("attachments");
if(to != null)
{
if(to.length>0)
{
String _to = "";
for(Object t : to)
{
_to += t + ";";
}
Dispatch.put(mail, "To", _to);
}
}
if(attachments != null)
{
if(attachments.length>0)
{
Dispatch attachs = Dispatch.get(mail, "Attachments").toDispatch();
for(Object attachment : attachments)
{
Dispatch.call(attachs, "Add", attachment);
}
}
}
//Dispatch.call(mail, "Send");
try {
Dispatch.call(mail, "Send");
} catch (com.jacob.com.ComFailException e) {
e.printStackTrace();
}
}
}
}
The line error is this line:
Dispatch.call(mail, "Send");
and the error states:
com.jacob.com.ComFailException:
A COM exception has been encountered:
At Invoke of: Send
Description: 80004004 / Operation aborted
Now I know my code is correct because if I do:
Dispatch.call(mail, "Save");
Then it does put that email I created into the Draft folder in Outlook:
So, what in the gobble gobble am I missing here in order to send it and not save it?
java eclipse outlook jacob
add a comment |
Hey all I am trying to send out an outlook email from Java using the JACOB COM activex code.
This is currently my code:
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import java.util.HashMap;
import java.util.Map;
public class MailOut implements com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
Map<String, Object> params = new HashMap<String, Object>();
String attachment = new String[1];
String to = new String[1];
public MailOut() {
}
public String exec(ITestExecutionServices tes, String args) {
//---------------------------------------------------------------------
params.put("subject", "Test subject");
params.put("body", "Please see attached.");
attachment[0] = "C:\temp\about_blank.pdf";
params.put("attachments", attachment);
to[0] = "me@here.com";
params.put("to", to);
OutlookJACOB mail = new OutlookJACOB();
mail.createEmail(params);
//---------------------------------------------------------------------
return "";
}
public class OutlookJACOB
{
private ActiveXComponent ol;
private Dispatch outlook;
private Object mapi = new Object[1];
private Object email = new Object[1];
public OutlookJACOB()
{
mapi[0] = "MAPI";
email[0] = 0;
ol = new ActiveXComponent("Outlook.Application");
//ol.setProperty("Visible", new Variant(true));
outlook = ol.getObject();
Dispatch.call(outlook,"GetNamespace",mapi).toDispatch();
}
public void createEmail(Map<String, Object> params)
{
Dispatch mail = Dispatch.call(outlook,"CreateItem",email).toDispatch();
Dispatch.put(mail, "Subject", params.get("subject"));
Dispatch.put(mail, "HTMLBody", params.get("body"));
String to = (String) params.get("to");
String attachments = (String) params.get("attachments");
if(to != null)
{
if(to.length>0)
{
String _to = "";
for(Object t : to)
{
_to += t + ";";
}
Dispatch.put(mail, "To", _to);
}
}
if(attachments != null)
{
if(attachments.length>0)
{
Dispatch attachs = Dispatch.get(mail, "Attachments").toDispatch();
for(Object attachment : attachments)
{
Dispatch.call(attachs, "Add", attachment);
}
}
}
//Dispatch.call(mail, "Send");
try {
Dispatch.call(mail, "Send");
} catch (com.jacob.com.ComFailException e) {
e.printStackTrace();
}
}
}
}
The line error is this line:
Dispatch.call(mail, "Send");
and the error states:
com.jacob.com.ComFailException:
A COM exception has been encountered:
At Invoke of: Send
Description: 80004004 / Operation aborted
Now I know my code is correct because if I do:
Dispatch.call(mail, "Save");
Then it does put that email I created into the Draft folder in Outlook:
So, what in the gobble gobble am I missing here in order to send it and not save it?
java eclipse outlook jacob
Hey all I am trying to send out an outlook email from Java using the JACOB COM activex code.
This is currently my code:
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import java.util.HashMap;
import java.util.Map;
public class MailOut implements com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
Map<String, Object> params = new HashMap<String, Object>();
String attachment = new String[1];
String to = new String[1];
public MailOut() {
}
public String exec(ITestExecutionServices tes, String args) {
//---------------------------------------------------------------------
params.put("subject", "Test subject");
params.put("body", "Please see attached.");
attachment[0] = "C:\temp\about_blank.pdf";
params.put("attachments", attachment);
to[0] = "me@here.com";
params.put("to", to);
OutlookJACOB mail = new OutlookJACOB();
mail.createEmail(params);
//---------------------------------------------------------------------
return "";
}
public class OutlookJACOB
{
private ActiveXComponent ol;
private Dispatch outlook;
private Object mapi = new Object[1];
private Object email = new Object[1];
public OutlookJACOB()
{
mapi[0] = "MAPI";
email[0] = 0;
ol = new ActiveXComponent("Outlook.Application");
//ol.setProperty("Visible", new Variant(true));
outlook = ol.getObject();
Dispatch.call(outlook,"GetNamespace",mapi).toDispatch();
}
public void createEmail(Map<String, Object> params)
{
Dispatch mail = Dispatch.call(outlook,"CreateItem",email).toDispatch();
Dispatch.put(mail, "Subject", params.get("subject"));
Dispatch.put(mail, "HTMLBody", params.get("body"));
String to = (String) params.get("to");
String attachments = (String) params.get("attachments");
if(to != null)
{
if(to.length>0)
{
String _to = "";
for(Object t : to)
{
_to += t + ";";
}
Dispatch.put(mail, "To", _to);
}
}
if(attachments != null)
{
if(attachments.length>0)
{
Dispatch attachs = Dispatch.get(mail, "Attachments").toDispatch();
for(Object attachment : attachments)
{
Dispatch.call(attachs, "Add", attachment);
}
}
}
//Dispatch.call(mail, "Send");
try {
Dispatch.call(mail, "Send");
} catch (com.jacob.com.ComFailException e) {
e.printStackTrace();
}
}
}
}
The line error is this line:
Dispatch.call(mail, "Send");
and the error states:
com.jacob.com.ComFailException:
A COM exception has been encountered:
At Invoke of: Send
Description: 80004004 / Operation aborted
Now I know my code is correct because if I do:
Dispatch.call(mail, "Save");
Then it does put that email I created into the Draft folder in Outlook:
So, what in the gobble gobble am I missing here in order to send it and not save it?
java eclipse outlook jacob
java eclipse outlook jacob
edited Nov 20 at 18:30
asked Nov 20 at 18:15
StealthRT
4,42927136253
4,42927136253
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You could refer to the below code:
ActiveXComponent oOutlook = new ActiveXComponent("Outlook.Application");
try {
DispatchEvents events = new DispatchEvents( oOutlook,
new InvocationProxy() {
public Variant invoke(String name, Variant args) {
_log.debug("Outlook got a "+name);
return null;
}
}
);
} catch (ComException cex) {
System.err.println("HR: " + Integer.toHexString(cex.getHResult()));
cex.printStackTrace();
}
Dispatch mail = Dispatch.invoke( oOutlook.getObject(), "CreateItem", Dispatch.Get, new Object { "0" }, new int[0]).toDispatch();
Dispatch.put(mail, "To", email );
Dispatch.put(mail, "Cc", cc );
Dispatch.put(mail, "Subject", "I am broke" );
Dispatch.put(mail, "Body", "Dear Beloved, Please send me cash. I am King of Nigeria. Thanks.");
Dispatch.put(mail, "ReadReceiptRequested", "true" );
Dispatch attachments = Dispatch.get(mail, "Attachments").toDispatch();
Dispatch.call(attachments, "Add", attachment );
Dispatch.call(mail,"Send");
oOutlook.safeRelease();
ComThread.Release();
For more information, Please refer to this link:
JACOB - Java COM Bridge
still get the com.jacob.com.ComFailException: A COM exception has been encountered: At Invoke of: Send
– StealthRT
Nov 29 at 20:44
Maybe this link will help for you: jabaco.org/board/660-outlook-on-jabaco-using-jacob.html
– Alina Li
Dec 3 at 1:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399112%2fjacob-com-outlook-send-mail-using-dispatch-call%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could refer to the below code:
ActiveXComponent oOutlook = new ActiveXComponent("Outlook.Application");
try {
DispatchEvents events = new DispatchEvents( oOutlook,
new InvocationProxy() {
public Variant invoke(String name, Variant args) {
_log.debug("Outlook got a "+name);
return null;
}
}
);
} catch (ComException cex) {
System.err.println("HR: " + Integer.toHexString(cex.getHResult()));
cex.printStackTrace();
}
Dispatch mail = Dispatch.invoke( oOutlook.getObject(), "CreateItem", Dispatch.Get, new Object { "0" }, new int[0]).toDispatch();
Dispatch.put(mail, "To", email );
Dispatch.put(mail, "Cc", cc );
Dispatch.put(mail, "Subject", "I am broke" );
Dispatch.put(mail, "Body", "Dear Beloved, Please send me cash. I am King of Nigeria. Thanks.");
Dispatch.put(mail, "ReadReceiptRequested", "true" );
Dispatch attachments = Dispatch.get(mail, "Attachments").toDispatch();
Dispatch.call(attachments, "Add", attachment );
Dispatch.call(mail,"Send");
oOutlook.safeRelease();
ComThread.Release();
For more information, Please refer to this link:
JACOB - Java COM Bridge
still get the com.jacob.com.ComFailException: A COM exception has been encountered: At Invoke of: Send
– StealthRT
Nov 29 at 20:44
Maybe this link will help for you: jabaco.org/board/660-outlook-on-jabaco-using-jacob.html
– Alina Li
Dec 3 at 1:51
add a comment |
You could refer to the below code:
ActiveXComponent oOutlook = new ActiveXComponent("Outlook.Application");
try {
DispatchEvents events = new DispatchEvents( oOutlook,
new InvocationProxy() {
public Variant invoke(String name, Variant args) {
_log.debug("Outlook got a "+name);
return null;
}
}
);
} catch (ComException cex) {
System.err.println("HR: " + Integer.toHexString(cex.getHResult()));
cex.printStackTrace();
}
Dispatch mail = Dispatch.invoke( oOutlook.getObject(), "CreateItem", Dispatch.Get, new Object { "0" }, new int[0]).toDispatch();
Dispatch.put(mail, "To", email );
Dispatch.put(mail, "Cc", cc );
Dispatch.put(mail, "Subject", "I am broke" );
Dispatch.put(mail, "Body", "Dear Beloved, Please send me cash. I am King of Nigeria. Thanks.");
Dispatch.put(mail, "ReadReceiptRequested", "true" );
Dispatch attachments = Dispatch.get(mail, "Attachments").toDispatch();
Dispatch.call(attachments, "Add", attachment );
Dispatch.call(mail,"Send");
oOutlook.safeRelease();
ComThread.Release();
For more information, Please refer to this link:
JACOB - Java COM Bridge
still get the com.jacob.com.ComFailException: A COM exception has been encountered: At Invoke of: Send
– StealthRT
Nov 29 at 20:44
Maybe this link will help for you: jabaco.org/board/660-outlook-on-jabaco-using-jacob.html
– Alina Li
Dec 3 at 1:51
add a comment |
You could refer to the below code:
ActiveXComponent oOutlook = new ActiveXComponent("Outlook.Application");
try {
DispatchEvents events = new DispatchEvents( oOutlook,
new InvocationProxy() {
public Variant invoke(String name, Variant args) {
_log.debug("Outlook got a "+name);
return null;
}
}
);
} catch (ComException cex) {
System.err.println("HR: " + Integer.toHexString(cex.getHResult()));
cex.printStackTrace();
}
Dispatch mail = Dispatch.invoke( oOutlook.getObject(), "CreateItem", Dispatch.Get, new Object { "0" }, new int[0]).toDispatch();
Dispatch.put(mail, "To", email );
Dispatch.put(mail, "Cc", cc );
Dispatch.put(mail, "Subject", "I am broke" );
Dispatch.put(mail, "Body", "Dear Beloved, Please send me cash. I am King of Nigeria. Thanks.");
Dispatch.put(mail, "ReadReceiptRequested", "true" );
Dispatch attachments = Dispatch.get(mail, "Attachments").toDispatch();
Dispatch.call(attachments, "Add", attachment );
Dispatch.call(mail,"Send");
oOutlook.safeRelease();
ComThread.Release();
For more information, Please refer to this link:
JACOB - Java COM Bridge
You could refer to the below code:
ActiveXComponent oOutlook = new ActiveXComponent("Outlook.Application");
try {
DispatchEvents events = new DispatchEvents( oOutlook,
new InvocationProxy() {
public Variant invoke(String name, Variant args) {
_log.debug("Outlook got a "+name);
return null;
}
}
);
} catch (ComException cex) {
System.err.println("HR: " + Integer.toHexString(cex.getHResult()));
cex.printStackTrace();
}
Dispatch mail = Dispatch.invoke( oOutlook.getObject(), "CreateItem", Dispatch.Get, new Object { "0" }, new int[0]).toDispatch();
Dispatch.put(mail, "To", email );
Dispatch.put(mail, "Cc", cc );
Dispatch.put(mail, "Subject", "I am broke" );
Dispatch.put(mail, "Body", "Dear Beloved, Please send me cash. I am King of Nigeria. Thanks.");
Dispatch.put(mail, "ReadReceiptRequested", "true" );
Dispatch attachments = Dispatch.get(mail, "Attachments").toDispatch();
Dispatch.call(attachments, "Add", attachment );
Dispatch.call(mail,"Send");
oOutlook.safeRelease();
ComThread.Release();
For more information, Please refer to this link:
JACOB - Java COM Bridge
answered Nov 22 at 7:03
Alina Li
606125
606125
still get the com.jacob.com.ComFailException: A COM exception has been encountered: At Invoke of: Send
– StealthRT
Nov 29 at 20:44
Maybe this link will help for you: jabaco.org/board/660-outlook-on-jabaco-using-jacob.html
– Alina Li
Dec 3 at 1:51
add a comment |
still get the com.jacob.com.ComFailException: A COM exception has been encountered: At Invoke of: Send
– StealthRT
Nov 29 at 20:44
Maybe this link will help for you: jabaco.org/board/660-outlook-on-jabaco-using-jacob.html
– Alina Li
Dec 3 at 1:51
still get the com.jacob.com.ComFailException: A COM exception has been encountered: At Invoke of: Send
– StealthRT
Nov 29 at 20:44
still get the com.jacob.com.ComFailException: A COM exception has been encountered: At Invoke of: Send
– StealthRT
Nov 29 at 20:44
Maybe this link will help for you: jabaco.org/board/660-outlook-on-jabaco-using-jacob.html
– Alina Li
Dec 3 at 1:51
Maybe this link will help for you: jabaco.org/board/660-outlook-on-jabaco-using-jacob.html
– Alina Li
Dec 3 at 1:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399112%2fjacob-com-outlook-send-mail-using-dispatch-call%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown