//on your form
protected void SendMail_Click(object sender, EventArgs e)
{
//send the mail
MailGoodies.Send(FromAddressText.Text, FromAddressText.Text, SubjectText.Text, BodyText.Text);
//Redirect to the Thank You Page
Response.Redirect("ThankYou.aspx");
}
using System;
using System.Configuration;
using System.Net.Mail;
//simple mailing class -- NOTE: you need to have access to SMTP server
public class MailGoodies
{
private const string MAIL_SERVER_CONFIG_KEY = "MailServer";
private const string DEFAULT_MAIL_SERVER = "localhost";
public static void Send(string FromAddress, string ToAddress, string Subject, string Body)
{
try{
SmtpClient Mailer = new SmtpClient(MailServer);
Mailer.Send(FromAddress, ToAddress, Subject, Body);
}
catch(Exception MailException)
{
throw new Exception(MailException.Message + Environment.NewLine + "occurred while sending the following email:" + Environment.NewLine + ToAddress + Environment.NewLine + Subject );
}
}
private static string MailServer{
get{
if(ConfigurationManager.AppSettings[MAIL_SERVER_CONFIG_KEY] != null)
return ConfigurationManager.AppSettings[MAIL_SERVER_CONFIG_KEY];
else
return DEFAULT_MAIL_SERVER;
}
}
}
Dean Fiala
Very Practical Software, Inc.