-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Arun Raj.C
Message 1 in Discussion






Sending email from ASP.Net 1.0 and 1.1 was
very easy. It is still easy with ASP.Net 2.0 - assuming you know the new class
names. I'm not sure why Microsoft changed these classes - certainly there is a
reason, I just don't know it yet. <o:p></o:p>


The System.Net.Mail
class is what replaced the System.Web.Mail class.
There are a number of classes within this class and it wasn't exactly clear to
me at first what was needed to send email. I messed with a number of the
classes trying to Dim a New object and then set properties like the way I'm
used to doing it, but no combinations I tried would work. <o:p></o:p>


What I did find was the System.Net.Mail.SmtpClient
class which has a method named Send. Rather than setting properties and calling
this method, I just wound up passing the values I wanted into this method -
doing all the "real" work on a single line. <o:p></o:p>


One property that you do need to set before
calling Send is the Host property so the class knows where to send the SMTP
email for delivery. <o:p></o:p>


I won't bore you with the simple form I
created to test this. I had four textboxes - "txtFrom"
for the sender email address, "txtTo" for
the email address I'm sending to, "txtSubj"
for the subject of the email, and "txtMsg"
for the body text of the email. <o:p></o:p>


These three lines do all of the work: <o:p></o:p>


Dim MailObj As New System.Net.Mail.SmtpClient

MailObj.Host = "localhost"

MailObj.Send(txtFrom.Text, txtTo.Text, txtSubj.Text, txtMsg.Text) <o:p></o:p>


The above assumes you are using the local SMTP
service on the machine where this code is running. You can also specify a
remote host but I don't know (yet) how to authenticate against a remote host
with SMTP-Auth (which most SMTP hosts are running now). <o:p></o:p>


Hopefully this will help someone else and save
them the time that I spent digging into this. If anyone reading this
understands the value of all the other System.Net.Mail
classes, please either send feedback to me and I'll
write something up, or put it in an article for the rest of us to see. 
<o:p></o:p>


Happy coding! <o:p></o:p>


Arun Raj.C<o:p></o:p>


http://spaces.msn.com/members/arunraj<o:p></o:p>


<o:p> </o:p>





-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to