473,385 Members | 1,531 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,385 software developers and data experts.

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.CreateObject("CDONTS.NewMail");
objMail.To = "so*****@someplace.com";
objMail.From = "me@me.com";
objMail.Subject = "Test";
objMail.Importance = 2;
objMail.MailFormat = 0;
objMail.BodyFormat = 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 3649
i think this may help u.

kapil
<%@ Import Namespace="System.Web.Mail" %>
<script language="c#" runat="server">
private void btnSend_Click(object sender, System.EventArgs e)
{

MailMessage msg = new MailMessage();

msg.To = txtTo.Text;
msg.From = txtFrom.Text;
msg.Subject = txtSubject.Text;
msg.Body = txtContent.Value;
lblStatus.Text = "Sending...";
SmtpMail.Send(msg);
lblStatus.Text = "Sent email (" + txtSubject.Text + ") to "
+txtTo.Text;
}
</script>
"Marty" <jo**********@yahoo.com> wrote in message
news:93**************************@posting.google.c om...
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 = "so*****@someplace.com";
objMail.From = "me@me.com";
objMail.Subject = "Test";
objMail.Importance = 2;
objMail.MailFormat = 0;
objMail.BodyFormat = 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
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:CDdontNetWrapper.dll
read the help for more inf. regarding Tlbimp.exe

2. Use late binding code shown bellow:

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

const int CdoBodyFormatText = 1;
const int CdoBodyFormatHTML = 0;
const int CdoMailFormatMime = 0;
const int CdoMailFormatText = 1;

Object EmailMessage;

//Create CDO message object
Type typDOM = Type.GetTypeFromProgID("cdonts.NewMail");
EmailMessage = Activator.CreateInstance(typDOM);

object[] param = new object[1];

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

//Subject
param[0] = subj;
typDOM.InvokeMember("Subject", BindingFlags.SetProperty, null, EmailMessage, param);

//Body
param[0] = contentBody;
typDOM.InvokeMember("Body", BindingFlags.SetProperty, null, EmailMessage, param);

//MailFormat
param[0] = CdoMailFormatText;
typDOM.InvokeMember("MailFormat", BindingFlags.SetProperty, null, EmailMessage, param);

//BodyFormat
param[0] = CdoBodyFormatText;
typDOM.InvokeMember("BodyFormat", BindingFlags.SetProperty, null, EmailMessage, param);


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


//Send the message
param[0] = null;
typDOM.InvokeMember("Send", BindingFlags.InvokeMethod,
null, EmailMessage, param);


}
catch (Exception ex)
{
System.Web.HttpContext.Current.Response.Write(ex.M essage);
}
}

//Enjoy
Sep 10 '05 #3

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

Similar topics

7
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...
2
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; ...
6
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...
2
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...
2
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...
5
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...
1
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...
7
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...
3
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 =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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 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.