473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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 = "in**@1and1.com"
objMM.From = email.Text

'If you want to CC this e-mail to someone else
'objMM.Cc = "su*****@1and1.com"

'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>
Aug 16 '08 #1
5 2395
Note: Since I wrote this I learned that System.Web.Mail is deppricated
"Henry Stock" <he***@henry-stock.comwrote in message
news:uz**************@TK2MSFTNGP03.phx.gbl...
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
<mailsettingssection 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 = "in**@1and1.com"
objMM.From = email.Text

'If you want to CC this e-mail to someone else
'objMM.Cc = "su*****@1and1.com"

'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>


Aug 16 '08 #2
re:
!Note: Since I wrote this I learned that System.Web.Mail is deppricated

Not for ASP.NET 1.1 apps.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Henry Stock" <he***@henry-stock.comwrote in message news:%2****************@TK2MSFTNGP06.phx.gbl...
Note: Since I wrote this I learned that System.Web.Mail is deppricated
"Henry Stock" <he***@henry-stock.comwrote in message
news:uz**************@TK2MSFTNGP03.phx.gbl...
>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
<mailsettingssection 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 = "in**@1and1.com"
objMM.From = email.Text

'If you want to CC this e-mail to someone else
'objMM.Cc = "su*****@1and1.com"

'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>



Aug 16 '08 #3
"Henry Stock" <he***@henry-stock.comwrote in message
news:uz**************@TK2MSFTNGP03.phx.gbl...
My ISP provides this sample for an ASP.NET capable email form.
What version of ASP.NET is running on your ISP's webserver?
I want to implement the code in a codebehind page instead of in the
mailform.aspx page.
Why? Despite what some people will tell you, there is absolutely no benefit
whatsoever in doing this. In fact, many well-respected developers prefer
this type of inline coding for aspx pages, and only use class pages for
common / shared functionality...
I also know that there are differences in background operations between
ASP.NET 1.1 and ASP.NET 2.0
There are - that's why you need to find out which version your ISP is
running...
Specifically I would like to test for a valid email address
http://www.google.co.uk/search?sourc...ess+validation
I want to convert the script from VB.NET to C#
There are dozens of online converters - GIYF...

But the first thing is to find out what version of ASP.NET your ISP is
running...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 16 '08 #4
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

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Henry Stock" <he***@henry-stock.comwrote in message
news:uz**************@TK2MSFTNGP03.phx.gbl...
>My ISP provides this sample for an ASP.NET capable email form.

What version of ASP.NET is running on your ISP's webserver?
>I want to implement the code in a codebehind page instead of in the
mailform.aspx page.

Why? Despite what some people will tell you, there is absolutely no
benefit whatsoever in doing this. In fact, many well-respected developers
prefer this type of inline coding for aspx pages, and only use class pages
for common / shared functionality...
>I also know that there are differences in background operations between
ASP.NET 1.1 and ASP.NET 2.0

There are - that's why you need to find out which version your ISP is
running...
>Specifically I would like to test for a valid email address

http://www.google.co.uk/search?sourc...ess+validation
>I want to convert the script from VB.NET to C#

There are dozens of online converters - GIYF...

But the first thing is to find out what version of ASP.NET your ISP is
running...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 16 '08 #5
"Henry Stock" <he***@henry-stock.comwrote in message
news:OO**************@TK2MSFTNGP03.phx.gbl...

[top-posting corrected]
>>I want to implement the code in a codebehind page instead of in the
mailform.aspx page.

Why? Despite what some people will tell you, there is absolutely no
benefit whatsoever in doing this. In fact, many well-respected developers
prefer this type of inline coding for aspx pages, and only use class
pages for common / shared functionality...

In answer to why use code behind page:
According to Microsoft it allows for cleaner separation of of code and
design issues.
That is completely incorrect.
>There are - that's why you need to find out which version your ISP is
running...

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
System.Net.Mail, then...
http://www.systemnetmail.com/
http://msdn.microsoft.com/en-us/libr...wc(VS.80).aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 16 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: pee2pee | last post by:
Hi, I have below code: <html> <head> <title>Contacting Worldpay, Please wait.......</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body...
6
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
30
by: btober | last post by:
Whenever I create a temporary table, with something like CREATE TEMPORARY TABLE temptable1 AS SELECT * FROM paid.ad_hoc_query; New schemas appear, with names like "pg_temp_1". I guess the...
7
by: GeorgeAtkins | last post by:
I want to create a web-based form or page that consists of a series of formatted questions and answers. The form will resemble an existing paper form. When the form is filled in, I want the user to...
0
Ganon11
by: Ganon11 | last post by:
The Miscellaneous Discussions forum is for any technology related question, comment, concern, or discussion. However, we encourage you to look at the full list of forums before deciding this is the...
1
by: vinodkus | last post by:
Problem 1I m writing a mail program in asp my first page is mail.asp where I subitting address, subject, body and second page is send_mail.asp Contents of Page mail.asp <html> <head> <meta...
2
by: prasenjit2007 | last post by:
Hello, can u help me sending Email with attachments using the Class phpMailer. On the website I have a link to an html form in which I input the parameters with the names 1)from(textbox name)...
3
uranuskid
by: uranuskid | last post by:
Hey folks, I was going to include a contact form on my website. Well, in the first place that seemed an easy thing to do with a form that prompts a PHP file validating the input vaiables and using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.