| Join | Help
in

Strong Coders Community

Where the extreme coders hang out.

mail script

Last post 03-20-2007 6:49 AM by Dean Fiala . 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-19-2007 11:18 AM
    • labyrinth248
    • Top 100 Contributor
    • Joined on 03-19-2007
    • Posts 1
    • Points 20

    mail script

    Reply Contact

    hey guys, I need to create a mail script that takes form input, generates an email and dumps the visiter at a thankyou page.

     any help?

    Thanks

    • Post Points: 20
  • 03-20-2007 6:49 AM In reply to
    • Dean Fiala
    • Top 10 Contributor
    • Joined on 10-17-2006
    • Posts 64
    • Points 830
    • MicrosoftMVP
      Moderator
      StrongCoders

    Re: mail script

    Reply Contact

    //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.
    • Post Points: 5
Page 1 of 1 (2 items)

Copyright © 2006-2007 Strong Coders Community. All rights reserved.
Privacy Statement | Terms Of Use | Advertise with us | Site Feedback

Powered by Community Server (Commercial Edition), by Telligent Systems