Monday, August 07, 2006

How to send a mail from the ASP.NET web form.



In .NET 2.0 we have SmtpClient class that allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP).
Namespace: System.Net.Mail

Example
protected void BtnSubmit_Click(object sender, EventArgs e)
{
if(!validateFields())
return;


SmtpClient smtpClient = new SmtpClient(host, port);
smtpClient.Credentials = new NetworkCredential(user, password);

MailAddress from = new MailAddress(EmailBox.Text, NameBox.Text);
MailAddress to = new MailAddress(to_mail);

MailMessage message = new MailMessage(from, to);
message.Subject = string.Format(subject_template, NameBox.Text, PhoneBox.Text);
message.Body = QuestionBox.Text;
try
{
smtpClient.Send(message);
Response.Redirect(redirect_success,true);
}
catch(Exception ex)
{
ErrorMessage = ex.Message;
Response.Redirect(redirect_error, true);
}
}

LandVP LLC

Wednesday, December 07, 2005

Programmatic Channel Registration

A remoting channel is any component that implements the IChannel interface. Both the client and the host application need to register which channels they wish to use, using the static method RegisterChannel of the ChannelServices class.

Host channels registration


The host must register at least one channel if it wants to export objects.

// Register TCP channel
IChannel channel = new TcpChannel(8005);
ChannelServices.RegisterChannel(channel);

// Register HTTP channel
IChannel channel = new HttpChannel(8006);
ChannelServices.RegisterChannel(channel);


LandVP LLC