Miscellaneous ASP.NET question on a mail form...

H

Henry Stock

My ISP provides this sample for an ASP.NET capable email form.

If you have any idea about how to do the following, I would greatly
appreciate your help.

I have a few alterations that I would like to implement, but I am not sure
where to begin.

First:

I want to implement the code in a codebehind page instead of in the
mailform.aspx page. I am not sure where I would put the code. I also know
that there are differences in background operations between ASP.NET 1.1 and
ASP.NET 2.0, but I don't know if the code would differ much. In other stuff
I found on the internet, the SMTP server was identified in a <mailsettings>
section in the web.config file. That seems cleaner to me, but I don't know
how the code would change. I probably would skip the code identifying the
server.

Second:

I already have an old mail form that was implemented using a CGI. I also
used a javascript based CAPTCHA function in that form to cut down on
automated spam.
In that instance the old form tag included and action attribute that pointed
to the cgi and an onsubmit="return jcap()" function that invoked the
javascript; elsewhere in the page there was a call to another javascript
that implemented the image that needed to be verified. I would still like
to use that script to prevent autospammers. I am not sure how to call the
javascript function jcap() before the contactUS_Click event handler.

The event handler is server based, so I am hoping that I can just leave the
call in the form onsubmit attribute because I think that should fire first.

As for the email based script I am guessing that I should check the
page.IsPostback variable and excute it only when that is true.

Third:
I want to add some additional validation on form fields. Specifically I
would like to test for a valid email address if nothing else. I am planning
a form that has more data elements such as name, address, phone number, etc
that I expect to concatenate into the message body.

Fourth:
I want to convert the script from VB.NET to C#


' ============================================
<% @Import Namespace="System.Web.Mail" %>
<script language="vb" runat="server">

Sub contactUS_Click(sender as Object, e as EventArgs)

'Create an instance of the MailMessage class
Dim objMM as New MailMessage()

objMM.To = "(e-mail address removed)"
objMM.From = email.Text

'If you want to CC this e-mail to someone else
'objMM.Cc = "(e-mail address removed)"

'e-mail format. Can be Text or Html
objMM.BodyFormat = MailFormat.Text

'Set the priority - options are High, Low, and Normal
objMM.Priority = MailPriority.Normal

'Set the subject
objMM.Subject = "1&1 Contact US"

'Set the body
objMM.Body = message.Text

'Smtp Server
SmtpMail.SmtpServer = "mrelay.perfora.net"

'Send the message
SmtpMail.Send(objMM)

panelSendEmail.Visible = false
panelMailSent.Visible = true

End Sub

</script>

<html>
<body>
<asp:panel id="panelSendEmail" runat="server">
<form runat="server">
<h2>CONTACT US FORM</h2>

<b>Your Name:</b>
<asp:textbox id="name" runat="server" />
<br>

<b>Your Email Address:</b>
<asp:textbox id="email" runat="server" />
<p>

<b>Your Message:</b><br>
<asp:textbox id="message" TextMode="MultiLine"
Columns="40" Rows="10" runat="server" />
<p>

<asp:button runat="server" id="contact_us" Text="Contact"
OnClick="contactUS_Click" />
</form>
</asp:panel>


<asp:panel id="panelMailSent" runat="server" Visible="False">
An e-mail has been sent. We will contact you soon!
</asp:panel>
</body>
</html>
 
J

Juan T. Llibre

re:
!> Note: Since I wrote this I learned that System.Web.Mail is deppricated

Not for ASP.NET 1.1 apps.
 
H

Henry Stock

In answer to why use code behind page:
According to Microsoft it allows for cleaner separation of of code and
design issues.



I wasn't clear on that. Sorry. My ISP is running ASP.NET 2.0. which is
good for me. I am trying to use the newsest stuff my tools will support and
I have Visual Studio 2005
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top