473,225 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

Reflection Question - Convert VBScript to C#

CJ
Hi

I'm trying to send email via a c# app, and I've come across various
ways to do it, but the way that seems best given my constraints is this
little vbscript:

Dim theApp, theNameSpace, theMailItem

set theApp = CreateObject("Outlook.Application")
Set theMailItem = theApp.CreateItem(0)

theMailItem.Recipients.Add you.n...@whatever.com
theMailItem.Subject = "Your Subject Here"
theMailItem.Body = "Your message here."
theMailItem.Send

So I'm trying to convert this to C#, but I'm stuck since I don't know
how to get the type of theMailItem. This is as far as I've got:

Type outlookType = Type.GetTypeFromProgID("Outlook.Application");
Object outlookApp = Activator.CreateInstance(outlookType);
Any ideas on how to convert the rest of the script?

Thanks

Jan 9 '06 #1
4 5768
Hi,
maybe you could just try to compile it using VB .NET or another late binding language like Boo and if it works translate it to C# using Reflector.

Regards,
stax
Jan 9 '06 #2
CJ,

You could do this in a similar manner in .NET, but that doesn't mean it
is the best way. Additionally, there are issues with the way that VB Script
runs in comparison to how code in the .NET environment runs (in particular,
accessing COM objects in .NET).

I would recommend using the facilities in .NET to do what you want. In
this case, look at the classes in the System.Net.Mail namespace. It will
allow you to send an email without Outlook being installed.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"CJ" <cj*********@mail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi

I'm trying to send email via a c# app, and I've come across various
ways to do it, but the way that seems best given my constraints is this
little vbscript:

Dim theApp, theNameSpace, theMailItem

set theApp = CreateObject("Outlook.Application")
Set theMailItem = theApp.CreateItem(0)

theMailItem.Recipients.Add you.n...@whatever.com
theMailItem.Subject = "Your Subject Here"
theMailItem.Body = "Your message here."
theMailItem.Send

So I'm trying to convert this to C#, but I'm stuck since I don't know
how to get the type of theMailItem. This is as far as I've got:

Type outlookType = Type.GetTypeFromProgID("Outlook.Application");
Object outlookApp = Activator.CreateInstance(outlookType);
Any ideas on how to convert the rest of the script?

Thanks

Jan 9 '06 #3
If you're just trying to send mail, then yes, absolutely, follow Nicholas's
advice. MAPI is ugly, nasty, 4-headed beast that resembles your
mother-in-law. System.Net.Mail sucks much much less. Lots of examples of
this and it's just as simple - a handful of lines of code, google away.

Craig

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eD*************@TK2MSFTNGP10.phx.gbl...
CJ,

You could do this in a similar manner in .NET, but that doesn't mean it
is the best way. Additionally, there are issues with the way that VB
Script runs in comparison to how code in the .NET environment runs (in
particular, accessing COM objects in .NET).

I would recommend using the facilities in .NET to do what you want. In
this case, look at the classes in the System.Net.Mail namespace. It will
allow you to send an email without Outlook being installed.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"CJ" <cj*********@mail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi

I'm trying to send email via a c# app, and I've come across various
ways to do it, but the way that seems best given my constraints is this
little vbscript:

Dim theApp, theNameSpace, theMailItem

set theApp = CreateObject("Outlook.Application")
Set theMailItem = theApp.CreateItem(0)

theMailItem.Recipients.Add you.n...@whatever.com
theMailItem.Subject = "Your Subject Here"
theMailItem.Body = "Your message here."
theMailItem.Send

So I'm trying to convert this to C#, but I'm stuck since I don't know
how to get the type of theMailItem. This is as far as I've got:

Type outlookType = Type.GetTypeFromProgID("Outlook.Application");
Object outlookApp = Activator.CreateInstance(outlookType);
Any ideas on how to convert the rest of the script?

Thanks


Jan 10 '06 #4
CJ
I know, you're right. But unfortunately in this instance I can
guarantee that our clients will be running Outlook, and that the
account my app will be running under will be a valid Outlook user. I
can't guarantee that they have a smtp server configured.

My first approach (after I ruled out smtp) was to use the
Microsoft.Interop stuff, but I wasn't sure what dlls I needed to
distribute (my project has 3 outlook-related dlls referenced -
Interop.Microsoft.Office.Core.dll, Interop.Outlook.dll, and
stdole.dll), which I was *allowed* to distribute, what would happen if
they have a different version of Outlook than the one I have on my dev
PC, etc etc. Someone then recommended the vbscript route, which seemed
to avoid a lot of these issues. Apparently just to bring up a lot of
issues of its own!

Craig S wrote:
If you're just trying to send mail, then yes, absolutely, follow Nicholas's
advice. MAPI is ugly, nasty, 4-headed beast that resembles your
mother-in-law. System.Net.Mail sucks much much less. Lots of examples of
this and it's just as simple - a handful of lines of code, google away.

Craig

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eD*************@TK2MSFTNGP10.phx.gbl...
CJ,

You could do this in a similar manner in .NET, but that doesn't mean it
is the best way. Additionally, there are issues with the way that VB
Script runs in comparison to how code in the .NET environment runs (in
particular, accessing COM objects in .NET).

I would recommend using the facilities in .NET to do what you want. In
this case, look at the classes in the System.Net.Mail namespace. It will
allow you to send an email without Outlook being installed.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"CJ" <cj*********@mail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi

I'm trying to send email via a c# app, and I've come across various
ways to do it, but the way that seems best given my constraints is this
little vbscript:

Dim theApp, theNameSpace, theMailItem

set theApp = CreateObject("Outlook.Application")
Set theMailItem = theApp.CreateItem(0)

theMailItem.Recipients.Add you.n...@whatever.com
theMailItem.Subject = "Your Subject Here"
theMailItem.Body = "Your message here."
theMailItem.Send

So I'm trying to convert this to C#, but I'm stuck since I don't know
how to get the type of theMailItem. This is as far as I've got:

Type outlookType = Type.GetTypeFromProgID("Outlook.Application");
Object outlookApp = Activator.CreateInstance(outlookType);
Any ideas on how to convert the rest of the script?

Thanks



Jan 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bill | last post by:
I need to convert a variable, nNum, into a two-character string. nNum is always less than 100. If nNum is 0, the string needs to be "00", if it's 1, it needs to be "01", if it's 34, it needs to...
2
by: davidgordon | last post by:
Hi, I have some pages with this VBScript code, which obviously does not work in Firefox. How can I convert this to Javascript in order for my web page to work in Firefox ? It basically fills a...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
4
by: Alicia | last post by:
Hi all, I have a problem with an Enum and Reflection. I am using an Xml and Reflection to create some controls, and to set their properties. All goes well until I encounter one property which is...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
2
by: Ronchese | last post by:
Hi all. Is possible I coerce a value to a determined type informed by a string? See the sample: dim obj as Object obj = SomeConversionType(2, "System.Windows.Forms.DockStyle")
2
by: LostnCode | last post by:
Hi, Can anyone help, I need to convert his code from vbscript to sharp C# for use with ASP.Net2.0? This is my first time using a forum. I don't know anything about either coding language so...
2
by: teecee99 | last post by:
This may be a dumb question but here goes. I have a retail web-site and back end order processing system built with vbscript that is currently hosted on GoDaddy on a shared hosting platform (i.e....
1
by: pyar | last post by:
Hi guys, I am trying since so long to resolve my query as how to Convert VBScript to DLL(.NET DLL).I browsed thru net but no use.So please could anyone of you guys help me out by giving a sample...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.