Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Outlook 2003 / Redemption / C# issue

55 views
Skip to first unread message

rbon...@gmail.com

unread,
Nov 16, 2005, 4:16:27 AM11/16/05
to
Hi,

I'm trying to generate .MSG, that outlook can use, inside a .NET web
application written in C#.
I tried to use Redemption DLL, but it seems that it doesn't work in C#
: the .msg file is never generated

Here's my code in C#, there's no exception thrown, COM permission are
set :

--------------------------------------------------------------------------------------------------------
Outlook.Application olApp = new Outlook.ApplicationClass();

Outlook.NameSpace olNS = olApp.GetNamespace("MAPI");
olNS.Logon(Missing.Value, Missing.Value, false, false);
SafeMailItem sItem = new Redemption.SafeMailItem();


MailItem oMsg = (MailItem)olApp.CreateItem (OlItemType.olMailItem );
//Outlook.MailItem oMsg = olApp.CreateItem(0) as Outlook.MailItem;
oMsg.To = "to...@toto.com";
oMsg.Subject = "RED";
oMsg.HTMLBody = "<HR>HELLO<BR>";

//oMsg.Save();
sItem.Item = oMsg;
sItem.SaveAs(@"c:\yyy.msg", Outlook.OlSaveAsType.olMSG);

olNS.Logoff();

olApp.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComObject (sItem);
System.Runtime.InteropServices.Marshal.ReleaseComObject (olApp);

sItem = null;
olApp = null;
--------------------------------------------------------------------------------------------------------
That's very weird because, I tried to translate the same code under VBA
(Excel) and it works fine (on the same computer).
--------------------------------------------------------------------------------------------------------
Dim OL As Outlook.Application
Dim msg2 As Outlook.MailItem
Dim sMsg As Redemption.SafeMailItem
Dim NameSpace As Outlook.NameSpace

Set OL = New Outlook.Application

Set NameSpace = OL.GetNamespace("MAPI")
NameSpace.Logon

Set msg2 = OL.CreateItem(olMailItem)

Set sMsg = New Redemption.SafeMailItem

msg2.To = "REDSo...@somewhere.com"
msg2.CC = "REDSo...@somewhere.com"
msg2.Subject = "REDTest email 300"
msg2.HTMLBody = "RED<HR>HELLO<BR>"


sMsg.Item = msg2

sMsg.Item.SaveAs "c:\zzz2.msg", thetype

OL.Quit
--------------------------------------------------------------------------------------------------------


Any ideas would be really appreciated.

Thanks in advance

Run-O

Sue Mosher [MVP-Outlook]

unread,
Nov 16, 2005, 8:44:15 AM11/16/05
to
Outlook is unsuitable to automate from server-based code. Any code to work with Outlook in a .NET web application would need to be client-side script, making use of the user's copy of Outlook.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


<rbon...@gmail.com> wrote in message news:1132132587....@g47g2000cwa.googlegroups.com...

rbon...@gmail.com

unread,
Nov 16, 2005, 12:52:12 PM11/16/05
to
Hi,

Thanks for your answer.

I really don't understand this state of fact.
Is there really a difference between automate outlook from VBA (Excel)
and from IIS ?
For instance, I succeeded automate word this way (IIS/COM), is outlook
different ?.

With which kind of client-side scripting would I be able to have
outlook opened on the client with a new mail generated dynamically (by
programmation : ie To, subject and htmlBody set) ?

I don't really know if it is possibe ?

Thanks in advance if you have an idea or a code sample.

Run-O

Sue Mosher [MVP-Outlook]

unread,
Nov 16, 2005, 1:42:02 PM11/16/05
to
Yes, there is a huge difference. Excel is a client application. IIS is a server application. THe KB article at http://support.microsoft.com/default.aspx?scid=kb;en-us;257757 explains the issues in detail, not just for Outlook, but for the other Office applications. Also consider, that unless you create the message on the client, under whose account will it be sent?

You can use either JScript or VBScript client-side scripting to create and display an email message in the context of the current user's Outlook profile. Note, however, that depending on the client security settings, the CreateObject("Outlook.Application") call may be blocked.

You might want to consider whether your application requires an HTML-format message. IF it doesn't, you might be able to use a simple mailto: URL.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


<rbon...@gmail.com> wrote in message news:1132163532.0...@g49g2000cwa.googlegroups.com...

rbon...@gmail.com

unread,
Nov 17, 2005, 7:38:28 AM11/17/05
to
Ok, many thanks for this explanation.
The workaround of using client-side scripting is working.
(Mailto doesn't fit my need because I need formating)

Here is the working code :
---------------------------------------------------

<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">

sub button1_onclick()

dim objOutlk 'Outlook
dim objMail 'Email item
dim strMsg
const olMailItem = 0

set objOutlk = createobject("Outlook.Application")
set objMail = objOutlk.createitem(olMailItem)
objMail.To = "TOte...@tt.com"
objMail.cc = "CCte...@tt.com"
objMail.subject = "subject testing"

objMail.HTMLBody = frm.htmlmsg.value
objMail.display

set objMail = nothing
set objOutlk = nothing

end sub
</SCRIPT>

</head>
<BODY>
<FORM name="frm">
<INPUT id=button1 name=button1 type=button value=Button>

<input type="hidden" name="htmlmsg" value="<table
border='1'><tr><td>Testing</td></tr></table><BR><HR>">

</FORM>
</BODY>


</HTML>

--------------------------------

Sue Mosher [MVP-Outlook]

unread,
Nov 17, 2005, 7:42:42 AM11/17/05
to
Great! Just curious: What control are you using for the formatted text input?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


<rbon...@gmail.com> wrote in message news:1132231108.3...@g44g2000cwa.googlegroups.com...

rbon...@gmail.com

unread,
Nov 17, 2005, 8:56:02 AM11/17/05
to
What do you mean by "control" ?

I project to use an asp:hidden field.

The strategy is to have pregenerated To/CC/Subject/HtmlBody in hidden
fields in the target web page.
When the user click on the button, a new ready-to-send email is
generated by vbscript (by the launch of outlook), that the user is
allowed to modify before sending.

By the way, do you know if there's a way to save the generated mail in
the draft folder, before displaying it to the user ?

Regards,

Run-O

Sue Mosher [MVP-Outlook]

unread,
Nov 17, 2005, 9:21:19 AM11/17/05
to
Any message that you create with Outlook objects automatically saves to the Drafts folder when you use MailItem.Save.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


<rbon...@gmail.com> wrote in message news:1132235762.7...@g47g2000cwa.googlegroups.com...

0 new messages