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, 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...
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
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...
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, 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...
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, 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...