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 4 5780
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
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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
by: Aaron Queenan |
last post by:
Given the classes:
class Class
{
public static implicit operator int(Class c)
{
return 0;
}
}
class Holder
|
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")
|
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...
|
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....
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |