Outlook and VB.NET

R

RTT

I'm creating a ASP.NET webapplication in VB.Net. In my code i create a mail
and when i use the save method it saves the mail in the draft folder. Do to
this i use the code i found at the link below and de outlook COM-objects in
Visual studio.

I found this code:
http://www.c-sharpcorner.com/Internet/SendingEmailsThroughOutlookCB.asp and
this work partly...

with this code i can save the mail in the draft folder. But i can't get it
to display to the user. mailitem.display does not seem to work.

so now i'm searching for a way to open or focus on the mail in outlook once
it's created....

does anybody has an idea how i can do this?
 
S

Sue Mosher [MVP-Outlook]

The code sample you found was for a Windows form application, not a web application. For a web application, you could create a web custom control using client-side Javascript to automate Outlook. Same methods, but different language.

For simple messages, you might even be able to just use a mailto: link.
 
R

RTT

do you have any documentatie, sites or keywords to search on to create a
javascript to automate outlook?

thxs anyway for the hint...

The code sample you found was for a Windows form application, not a web
application. For a web application, you could create a web custom control
using client-side Javascript to automate Outlook. Same methods, but
different language.

For simple messages, you might even be able to just use a mailto: link.
 
S

Sue Mosher [MVP-Outlook]

The sample at http://www.outlookcode.com/d/code/formonweb.htm shows how to create a new item using a custom form. The important thing for you is that it shows how to instantiate the Outlook.Application object. As I said before, beyond that, the techniques are the same as in .NET -- in other words, you're using the same Outlook object model.

Note that you will have ActiveX security issues to deal with, since Outlook is not considered "safe for scripting."

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
R

RTT

automation server can't create object.

when i try the script i receive this error. does this script work with the
outlook of the local machine of with the one on the server? Because the
script will run on a server, but i want to create the email in the outlook
running on the clientside. or is there an other cause of that error?

The sample at http://www.outlookcode.com/d/code/formonweb.htm shows how to
create a new item using a custom form. The important thing for you is that
it shows how to instantiate the Outlook.Application object. As I said
before, beyond that, the techniques are the same as in .NET -- in other
words, you're using the same Outlook object model.

Note that you will have ActiveX security issues to deal with, since Outlook
is not considered "safe for scripting."

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

The script runs on the client, not the server. That's the whole point -- to work with the copy of Outlook running on the client.

As I said, you may run into security issues when instantiating an Outlook.Application object on the client, both because of browser security and because some anti-virus programs block access to that object.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
R

RTT

thxs a lot... added to site to my trusted sites and now it works... thanks
for the great tips.

maybe one last question. I want to create a mail with different people in
the replyto. mailitem.replyrecepients doesn't seem to work. any idea..

thxs anyway, you've been a great help... couldn't have done it without your
help...

The script runs on the client, not the server. That's the whole point -- to
work with the copy of Outlook running on the client.

As I said, you may run into security issues when instantiating an
Outlook.Application object on the client, both because of browser security
and because some anti-virus programs block access to that object.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

ReplyRecipients is the right property. Remember, though, that it's a collection, like Recipients. You have to use the Add method to populate it.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
R

RTT

you've been a great help so far... thxs

but when i use
omailitem.to = "[email protected]" it works
but when i have an array with the emailadresses and i use recepients (or
replyrecepients) like this:
for(var x=0;x<tmp.Length;x++) {
oMailItem.Recipients.Add(tmp[x]);
}
that doesn't work. i receive this error:
there must be at least one name or distribution list in the to, cc or bcc
box.




ReplyRecipients is the right property. Remember, though, that it's a
collection, like Recipients. You have to use the Add method to populate it.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

Did you use Recipients.ResolveAll to resolve recipients before sending?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



RTT said:
you've been a great help so far... thxs

but when i use
omailitem.to = "[email protected]" it works
but when i have an array with the emailadresses and i use recepients (or
replyrecepients) like this:
for(var x=0;x<tmp.Length;x++) {
oMailItem.Recipients.Add(tmp[x]);
}
that doesn't work. i receive this error:
there must be at least one name or distribution list in the to, cc or bcc
box.

ReplyRecipients is the right property. Remember, though, that it's a
collection, like Recipients. You have to use the Add method to populate it.

RTT said:
thxs a lot... added to site to my trusted sites and now it works... thanks
for the great tips.

maybe one last question. I want to create a mail with different people in
the replyto. mailitem.replyrecepients doesn't seem to work. any idea..

The script runs on the client, not the server. That's the whole point -- to
work with the copy of Outlook running on the client.

As I said, you may run into security issues when instantiating an
Outlook.Application object on the client, both because of browser security
and because some anti-virus programs block access to that object.
 
R

RTT

this is my complete code:

oApp = new ActiveXObject("Outlook.Application"); oNameSpace =
oApp.GetNamespace("MAPI"); oMailItem = oApp.CreateItem(oApp.olMailItem);
oMailItem.HTMLBody = document.Form1.Hbody.value;
//oMailItem.To = document.Form1.Hresourceowner.value;
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x < tmp.length;x++) {
oMailItem.Recipients.Add(tmp[x]);
} oMailItem.Subject = "Booking Request";
oMailItem.VotingOptions = "Booked; Not Booked";
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x<tmp.length;x++) {
oMailItem.ReplyRecipients.Add(tmp[x]);
}
oMailItem.Display();

the error appears at oMailItem.Recipients.Add(tmp[x]); so it's before
sending and before displaying...
document.Form1.Hresourceowner.value and document.Form1.Hresourceowner.value
is a string with comma spererated emailsaddresses...

don't know why it isn't working


Did you use Recipients.ResolveAll to resolve recipients before sending?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



RTT said:
you've been a great help so far... thxs

but when i use
omailitem.to = "[email protected]" it works
but when i have an array with the emailadresses and i use recepients (or
replyrecepients) like this:
for(var x=0;x<tmp.Length;x++) {
oMailItem.Recipients.Add(tmp[x]);
}
that doesn't work. i receive this error:
there must be at least one name or distribution list in the to, cc or bcc
box.

ReplyRecipients is the right property. Remember, though, that it's a
collection, like Recipients. You have to use the Add method to populate it.

RTT said:
thxs a lot... added to site to my trusted sites and now it works... thanks
for the great tips.

maybe one last question. I want to create a mail with different people in
the replyto. mailitem.replyrecepients doesn't seem to work. any idea..

The script runs on the client, not the server. That's the whole point -- to
work with the copy of Outlook running on the client.

As I said, you may run into security issues when instantiating an
Outlook.Application object on the client, both because of browser security
and because some anti-virus programs block access to that object.
 
S

Sue Mosher [MVP-Outlook]

That makes no sense. Outlook doesn't care about the recipients until you actually execute Send.

I'm afraid I'm just a humble VB programmer, so I can follow along only up to a point, but I can't suggest any actually code changes and certainly can't speak about string to array converstions.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



RTT said:
this is my complete code:

oApp = new ActiveXObject("Outlook.Application"); oNameSpace =
oApp.GetNamespace("MAPI"); oMailItem = oApp.CreateItem(oApp.olMailItem);
oMailItem.HTMLBody = document.Form1.Hbody.value;
//oMailItem.To = document.Form1.Hresourceowner.value;
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x < tmp.length;x++) {
oMailItem.Recipients.Add(tmp[x]);
} oMailItem.Subject = "Booking Request";
oMailItem.VotingOptions = "Booked; Not Booked";
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x<tmp.length;x++) {
oMailItem.ReplyRecipients.Add(tmp[x]);
}
oMailItem.Display();

the error appears at oMailItem.Recipients.Add(tmp[x]); so it's before
sending and before displaying...
document.Form1.Hresourceowner.value and document.Form1.Hresourceowner.value
is a string with comma spererated emailsaddresses...

don't know why it isn't working


Did you use Recipients.ResolveAll to resolve recipients before sending?

RTT said:
you've been a great help so far... thxs

but when i use
omailitem.to = "[email protected]" it works
but when i have an array with the emailadresses and i use recepients (or
replyrecepients) like this:
for(var x=0;x<tmp.Length;x++) {
oMailItem.Recipients.Add(tmp[x]);
}
that doesn't work. i receive this error:
there must be at least one name or distribution list in the to, cc or bcc
box.

ReplyRecipients is the right property. Remember, though, that it's a
collection, like Recipients. You have to use the Add method to populate it.

RTT said:
thxs a lot... added to site to my trusted sites and now it works... thanks
for the great tips.

maybe one last question. I want to create a mail with different people in
the replyto. mailitem.replyrecepients doesn't seem to work. any idea..
 
R

RTT

string to array is done by the split(;)
with that you receive a array of strings...


That makes no sense. Outlook doesn't care about the recipients until you
actually execute Send.

I'm afraid I'm just a humble VB programmer, so I can follow along only up to
a point, but I can't suggest any actually code changes and certainly can't
speak about string to array converstions.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



RTT said:
this is my complete code:

oApp = new ActiveXObject("Outlook.Application"); oNameSpace =
oApp.GetNamespace("MAPI"); oMailItem = oApp.CreateItem(oApp.olMailItem);
oMailItem.HTMLBody = document.Form1.Hbody.value;
//oMailItem.To = document.Form1.Hresourceowner.value;
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x < tmp.length;x++) {
oMailItem.Recipients.Add(tmp[x]);
} oMailItem.Subject = "Booking Request";
oMailItem.VotingOptions = "Booked; Not Booked";
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x<tmp.length;x++) {
oMailItem.ReplyRecipients.Add(tmp[x]);
}
oMailItem.Display();

the error appears at oMailItem.Recipients.Add(tmp[x]); so it's before
sending and before displaying...
document.Form1.Hresourceowner.value and document.Form1.Hresourceowner.value
is a string with comma spererated emailsaddresses...

don't know why it isn't working


Did you use Recipients.ResolveAll to resolve recipients before sending?

RTT said:
you've been a great help so far... thxs

but when i use
omailitem.to = "[email protected]" it works
but when i have an array with the emailadresses and i use recepients (or
replyrecepients) like this:
for(var x=0;x<tmp.Length;x++) {
oMailItem.Recipients.Add(tmp[x]);
}
that doesn't work. i receive this error:
there must be at least one name or distribution list in the to, cc or bcc
box.

ReplyRecipients is the right property. Remember, though, that it's a
collection, like Recipients. You have to use the Add method to populate it.

RTT said:
thxs a lot... added to site to my trusted sites and now it works... thanks
for the great tips.

maybe one last question. I want to create a mail with different people in
the replyto. mailitem.replyrecepients doesn't seem to work. any idea..
 
S

Sue Mosher [MVP-Outlook]

I don't see any split function in the code below.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



RTT said:
string to array is done by the split(;)
with that you receive a array of strings...


That makes no sense. Outlook doesn't care about the recipients until you
actually execute Send.

I'm afraid I'm just a humble VB programmer, so I can follow along only up to
a point, but I can't suggest any actually code changes and certainly can't
speak about string to array converstions.

RTT said:
this is my complete code:

oApp = new ActiveXObject("Outlook.Application"); oNameSpace =
oApp.GetNamespace("MAPI"); oMailItem = oApp.CreateItem(oApp.olMailItem);
oMailItem.HTMLBody = document.Form1.Hbody.value;
//oMailItem.To = document.Form1.Hresourceowner.value;
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x < tmp.length;x++) {
oMailItem.Recipients.Add(tmp[x]);
} oMailItem.Subject = "Booking Request";
oMailItem.VotingOptions = "Booked; Not Booked";
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x<tmp.length;x++) {
oMailItem.ReplyRecipients.Add(tmp[x]);
}
oMailItem.Display();

the error appears at oMailItem.Recipients.Add(tmp[x]); so it's before
sending and before displaying...
document.Form1.Hresourceowner.value and document.Form1.Hresourceowner.value
is a string with comma spererated emailsaddresses...

don't know why it isn't working


Did you use Recipients.ResolveAll to resolve recipients before sending?

RTT said:
you've been a great help so far... thxs

but when i use
omailitem.to = "[email protected]" it works
but when i have an array with the emailadresses and i use recepients (or
replyrecepients) like this:
for(var x=0;x<tmp.Length;x++) {
oMailItem.Recipients.Add(tmp[x]);
}
that doesn't work. i receive this error:
there must be at least one name or distribution list in the to, cc or bcc
box.

ReplyRecipients is the right property. Remember, though, that it's a
collection, like Recipients. You have to use the Add method to populate it.

thxs a lot... added to site to my trusted sites and now it works... thanks
for the great tips.

maybe one last question. I want to create a mail with different people in
the replyto. mailitem.replyrecepients doesn't seem to work. any idea..
 
R

RTT

pasted from the wrong version. it should be like this:

var tmp = document.Form1.Hresourceowner.value.split(";")
for(var x=0;x < tmp.length;x++) {
.......

problem remains the same....

I don't see any split function in the code below.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



RTT said:
string to array is done by the split(;)
with that you receive a array of strings...


That makes no sense. Outlook doesn't care about the recipients until you
actually execute Send.

I'm afraid I'm just a humble VB programmer, so I can follow along only up to
a point, but I can't suggest any actually code changes and certainly can't
speak about string to array converstions.

RTT said:
this is my complete code:

oApp = new ActiveXObject("Outlook.Application"); oNameSpace =
oApp.GetNamespace("MAPI"); oMailItem = oApp.CreateItem(oApp.olMailItem);
oMailItem.HTMLBody = document.Form1.Hbody.value;
//oMailItem.To = document.Form1.Hresourceowner.value;
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x < tmp.length;x++) {
oMailItem.Recipients.Add(tmp[x]);
} oMailItem.Subject = "Booking Request";
oMailItem.VotingOptions = "Booked; Not Booked";
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x<tmp.length;x++) {
oMailItem.ReplyRecipients.Add(tmp[x]);
}
oMailItem.Display();

the error appears at oMailItem.Recipients.Add(tmp[x]); so it's before
sending and before displaying...
document.Form1.Hresourceowner.value and document.Form1.Hresourceowner.value
is a string with comma spererated emailsaddresses...

don't know why it isn't working


Did you use Recipients.ResolveAll to resolve recipients before sending?

RTT said:
you've been a great help so far... thxs

but when i use
omailitem.to = "[email protected]" it works
but when i have an array with the emailadresses and i use recepients (or
replyrecepients) like this:
for(var x=0;x<tmp.Length;x++) {
oMailItem.Recipients.Add(tmp[x]);
}
that doesn't work. i receive this error:
there must be at least one name or distribution list in the to, cc or bcc
box.

ReplyRecipients is the right property. Remember, though, that it's a
collection, like Recipients. You have to use the Add method to populate it.

thxs a lot... added to site to my trusted sites and now it works... thanks
for the great tips.

maybe one last question. I want to create a mail with different people in
the replyto. mailitem.replyrecepients doesn't seem to work. any idea..
 
S

Sue Mosher [MVP-Outlook]

It still makes no sense that you'd get that error before the Send command executes. Did you try adding ResolveAll? I have no further suggestions.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



RTT said:
pasted from the wrong version. it should be like this:

var tmp = document.Form1.Hresourceowner.value.split(";")
for(var x=0;x < tmp.length;x++) {
......

problem remains the same....

I don't see any split function in the code below.
RTT said:
string to array is done by the split(;)
with that you receive a array of strings...


That makes no sense. Outlook doesn't care about the recipients until you
actually execute Send.

RTT said:
this is my complete code:

oApp = new ActiveXObject("Outlook.Application"); oNameSpace =
oApp.GetNamespace("MAPI"); oMailItem = oApp.CreateItem(oApp.olMailItem);
oMailItem.HTMLBody = document.Form1.Hbody.value;
//oMailItem.To = document.Form1.Hresourceowner.value;
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x < tmp.length;x++) {
oMailItem.Recipients.Add(tmp[x]);
} oMailItem.Subject = "Booking Request";
oMailItem.VotingOptions = "Booked; Not Booked";
var tmp = document.Form1.Hresourceowner.value;
for(var x=0;x<tmp.length;x++) {
oMailItem.ReplyRecipients.Add(tmp[x]);
}
oMailItem.Display();

the error appears at oMailItem.Recipients.Add(tmp[x]); so it's before
sending and before displaying...
document.Form1.Hresourceowner.value and document.Form1.Hresourceowner.value
is a string with comma spererated emailsaddresses...

don't know why it isn't working


Did you use Recipients.ResolveAll to resolve recipients before sending?

you've been a great help so far... thxs

but when i use
omailitem.to = "[email protected]" it works
but when i have an array with the emailadresses and i use recepients (or
replyrecepients) like this:
for(var x=0;x<tmp.Length;x++) {
oMailItem.Recipients.Add(tmp[x]);
}
that doesn't work. i receive this error:
there must be at least one name or distribution list in the to, cc or bcc
box.

ReplyRecipients is the right property. Remember, though, that it's a
collection, like Recipients. You have to use the Add method to populate
it.

thxs a lot... added to site to my trusted sites and now it works...
thanks
for the great tips.

maybe one last question. I want to create a mail with different people in
the replyto. mailitem.replyrecepients doesn't seem to work. any idea..
 
Top