Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call object from c#

Status
Not open for further replies.

iis6newbie

Technical User
Nov 22, 2003
54
0
0
US

Hello all,

I have the following code in vb.net. I would like to convert to c# .NET. Can someone help me?

Set Mail = CreateObject ("CDOMail.CSendMail") ' in vb.net


Thanks
 
Umm, I wouldn't use the CDOMail object like this -- I would call System.Web.Mail.SmtpMail, which provides a .NET managed wrapper around it. Thus, you wouldn't need to translate the awkward COM call yourself.
msdn said:
try
{
try
{
MailMessage Message = new MailMessage();
Message.To = "someone@example.com";
Message.From = "you@example.com";
Message.Subject = "test msg";
Message.Body = "body goes here";

try
{
SmtpMail.SmtpServer = "your mail server name goes here";
SmtpMail.Send(Message);
}
catch(System.Web.HttpException ehttp)
{
Console.WriteLine("{0}", ehttp.Message);
Console.WriteLine("Here is the full error message output");
Console.Write("{0}", ehttp.ToString());
}
}
catch(IndexOutOfRangeException)
{
// Show proper usage
}
}
catch(System.Exception e)
{
Console.WriteLine("Unknown Exception occurred {0}", e.Message);
Console.WriteLine("Here is the Full Message output");
Console.WriteLine("{0}", e.ToString());
}
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks for you reply. The problem is that I work for someone, and this person wants me to use the object that has been build in vb6 which is "CDOMail.CSendMail". He does not want me to use smtp server. He wants me to use exchange server to resolve the badge number.

 
Read the documentation. SmtpMail is a wrapper around CDO. The difference is that the SmtpMail class has already done the hard work for you, and made it into a .NET class that's much easier to use than calling CDO yourself.

If you're writing a .NET application, you would be best to stay in the .NET world as much as possible.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top