473,782 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Send ing Email with CDonts and C#

ASP.Net, C#, Email message, CDonts not CDO

I am writing an ASP.Net application where I cannot use CDO. I must
use CDonts. I cannot find an example of this on the Internet. I only
see examples on how to do this using CDO. Unfortunately, I don't have
that option. I must use C# and CDonts. Do you have any ideas or
code?

In traditional ASP, the code was:
objMail = Server.CreateOb ject("CDONTS.Ne wMail");
objMail.To = "so*****@somepl ace.com";
objMail.From = "me@me.com" ;
objMail.Subject = "Test";
objMail.Importa nce = 2;
objMail.MailFor mat = 0;
objMail.BodyFor mat = 0;
objMail.Body = "Test message";
objMail.Send;

How is that ported to .Net in C#? What do you declare the objMail
variable? I tried it as an object variable and .Net didn't like it.

Thanks,
Marty
Jul 21 '05 #1
2 3679
i think this may help u.

kapil
<%@ Import Namespace="Syst em.Web.Mail" %>
<script language="c#" runat="server">
private void btnSend_Click(o bject sender, System.EventArg s e)
{

MailMessage msg = new MailMessage();

msg.To = txtTo.Text;
msg.From = txtFrom.Text;
msg.Subject = txtSubject.Text ;
msg.Body = txtContent.Valu e;
lblStatus.Text = "Sending... ";
SmtpMail.Send(m sg);
lblStatus.Text = "Sent email (" + txtSubject.Text + ") to "
+txtTo.Text;
}
</script>
"Marty" <jo**********@y ahoo.com> wrote in message
news:93******** *************** ***@posting.goo gle.com...
ASP.Net, C#, Email message, CDonts not CDO

I am writing an ASP.Net application where I cannot use CDO. I must
use CDonts. I cannot find an example of this on the Internet. I only
see examples on how to do this using CDO. Unfortunately, I don't have
that option. I must use C# and CDonts. Do you have any ideas or
code?

In traditional ASP, the code was:
objMail = Server.CreateOb ject("CDONTS.Ne wMail");
objMail.To = "so*****@somepl ace.com";
objMail.From = "me@me.com" ;
objMail.Subject = "Test";
objMail.Importa nce = 2;
objMail.MailFor mat = 0;
objMail.BodyFor mat = 0;
objMail.Body = "Test message";
objMail.Send;

How is that ported to .Net in C#? What do you declare the objMail
variable? I tried it as an object variable and .Net didn't like it.

Thanks,
Marty

Jul 21 '05 #2
claudirim
1 New Member
C#.Net does not support unmanaged COM code unlike Vbscript and VB.Net.
To achieve the same functionally as in Visual Basic there are 2 steps that you can follow:

1. Create a wrapper class for the unmanaged COM code.
using "The type library importer" (tlbimp) command line tool:

e.g. tlbimp CDonts.dll /out:CDdontNetWr apper.dll
read the help for more inf. regarding Tlbimp.exe

2. Use late binding code shown bellow:

public void sendEmail(strin g subj, string afrom, string toemal, string contentBody){
try
{

const int CdoBodyFormatTe xt = 1;
const int CdoBodyFormatHT ML = 0;
const int CdoMailFormatMi me = 0;
const int CdoMailFormatTe xt = 1;

Object EmailMessage;

//Create CDO message object
Type typDOM = Type.GetTypeFro mProgID("cdonts .NewMail");
EmailMessage = Activator.Creat eInstance(typDO M);

object[] param = new object[1];

//Set email adress, subject And body
param[0] = toemal;
typDOM.InvokeMe mber("To", BindingFlags.Se tProperty, null, EmailMessage, param);

//Subject
param[0] = subj;
typDOM.InvokeMe mber("Subject", BindingFlags.Se tProperty, null, EmailMessage, param);

//Body
param[0] = contentBody;
typDOM.InvokeMe mber("Body", BindingFlags.Se tProperty, null, EmailMessage, param);

//MailFormat
param[0] = CdoMailFormatTe xt;
typDOM.InvokeMe mber("MailForma t", BindingFlags.Se tProperty, null, EmailMessage, param);

//BodyFormat
param[0] = CdoBodyFormatTe xt;
typDOM.InvokeMe mber("BodyForma t", BindingFlags.Se tProperty, null, EmailMessage, param);


//Set sender address If specified.
if (afrom.Length > 0)
{
param[0] = afrom;
typDOM.InvokeMe mber("From", BindingFlags.Se tProperty, null, EmailMessage, param);
}


//Send the message
param[0] = null;
typDOM.InvokeMe mber("Send", BindingFlags.In vokeMethod,
null, EmailMessage, param);


}
catch (Exception ex)
{
System.Web.Http Context.Current .Response.Write (ex.Message);
}
}

//Enjoy
Sep 10 '05 #3

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

Similar topics

7
2547
by: Mario Leduc | last post by:
Hi, I have a page that sends user comments with CDONTS, works fine. Until I put a URL (http://192.168.0.1). If I use http://domain.com it works fine. Why with the numeric URL, CDONTS does not send the mail?? Thanks
2
1887
by: Jammer | last post by:
Can someone give me some sample code to use CDONTS.new to send email with an attachment? I've got sample code from the following website; http://msdn.microsoft.com/library/en-us/cdo/html/_denali_newmail_object_cdonts_library_.asp?frame=true But, I'm having trouble GETTING the relevant field from my HTML form! I can't seem to be able to get the field property. :( It just comes up as a blank.
6
11188
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I will include the code I originally used. I understand I should switch from CDONTS to CDO mail but after several sttempts I am finding a very hard time getting the new CDO mail to work properly. Any assistance with this would be greatly...
2
9386
by: microsoft.public.dotnet.languages.csharp | last post by:
ASP.Net, C#, Email message, CDonts not CDO I am writing an ASP.Net application where I cannot use CDO. I must use CDonts. I cannot find an example of this on the Internet. I only see examples on how to do this using CDO. Unfortunately, I don't have that option. I must use C# and CDonts. Do you have any ideas or code? In traditional ASP, the code was: objMail = Server.CreateObject("CDONTS.NewMail"); objMail.To =...
2
4537
by: Paul Turley | last post by:
How do I format a message so it shows up as a web page in the mail reader. In the body of my message, I'm including a '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Traditional//EN">' tag and standard <html><body> tags but this all shows up as text in the message. What's the secret? -- Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician paul@createsolutions.net
5
8798
by: Andreas | last post by:
I am working with three computers, my developing computer, a Web Server and a Mail Server (Exchange). I am trying to send a email from the Web Server via the Mail Server to a valid email address with this code: MailMessage msgMail = new MailMessage(); msgMail.To = "test@address.com"; msgMail.From = "from@address.com"; msgMail.Subject = "Mail Example Subject";
1
383
by: Marty | last post by:
ASP.Net, C#, Email message, CDonts not CDO I am writing an ASP.Net application where I cannot use CDO. I must use CDonts. I cannot find an example of this on the Internet. I only see examples on how to do this using CDO. Unfortunately, I don't have that option. I must use C# and CDonts. Do you have any ideas or code? In traditional ASP, the code was: objMail = Server.CreateObject("CDONTS.NewMail");
7
2809
by: Ron Hinds | last post by:
Our webserver is currently Windows 2000 Server. Many of our pages send mail using the CDONTS object library. It is simple and very straightforward. We have built a new webserver using Windows Server 2003 Web Edition. Unfortunately, 2003 doesn't have the CDONTS library anymore. I'm looking for a new solution that is preferably as easy to use. But I would also like some additional functionality. The webserver will be hosting five web...
3
3465
by: Prasad | last post by:
Hi all, I had to write a page in ASP which sends an email. I googled and was able to write the following code: <html> <body> <% Set Mail = Server.CreateObject("CDONTS.NewMail") Mail.To = "XXXXXXXXXXXX@XXXXXX.COM"
0
9641
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.