zimcoder Level: VB Lord

 Registered: 27-10-2003 Posts: 225
|
Re: how i can send mail with asp .net??
first make sure you have an smtp server running on your machine
include the namespace for mail by doing the following:
in C#
using System.Web.Mail;
then
create an instance of the mailmessage class as follows:
MailMessage MyEmail = new MailMessage();
MyEmail.To = txtTo.Text;
MyEmail.From = txtFrom.Text;
MyEmail.Cc = txtCc.Text;
MyEmail.Subject = "Sample Email";
MyEmail.Body = txtName.Text + ", " + txtComments.Text;
//you can set your mail priority if you want
MyEmail.Priority = MailPriority.High;
try
{
SmtpMail.Send(MyEmail);
Response.Write("Email has been sent !");
}
catch (Exception ex)
{
Response.Write("Sorry your message was not sent because: " + ex.ToString());
}
VB.Net
Imports System.Web.Mail;
Dim MyEmail as New MailMessage()
MyEmail.To = txtTo.Text
MyEmail.From = txtFrom.Text
MyEmail.Cc = txtCc.Text
MyEmail.Subject = "Test Email"
MyEmail.Body = txtName.Text & ", " &txtComments.Text
objEmail.Priority = MailPriority.High
try
SmtpMail.Send(MyEMail)
Response.Write(Your E-mail has been sent !)
catch ex as Exception
Response.Write("Sorry your message was not sent because: " + ex.ToString)
End Try
hope you find this helpful
____________________________
BrainBench ADO.NET and ASP.NET Certified Developer
 
|