how can i send an email when a form is submitted?

I just have a couple forms and the Submit button does this:   sqldatasource1.insert()

I want to send an email when the form has been submitted to one email address.  I don't really need all of the form fields in the email address, except for one txtClientName.  

How can I write code to send email through smtp.gmail.com to one email address with the subject "An order has been submitted" and in the body "[txtClientName] has submitted a new order!"

Its a very simple email, just basically a "hey go check the orders" kind of thing...

If you could give me the code for the smtp setup as well as how to put hte message in, and how to tell the submit button to also send the email.  I'd really appreciate it!!
georgem767Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bhnmiCommented:
<%@ Page Language="VB" EnableSessionState="False"  
EnableViewState="False" Trace="False" Debug="False"%>
<%@ Import Namespace="System.Web.Mail" %>  
<script language="VB" runat=server>  

Sub Page_Load(Sender as Object, E as EventArgs)  
   If Page.IsPostBack Then
       lblResponse.Text = "Your problem has been reported."
   End If
End Sub  
   
Sub btn_Click(sender as Object, e as System.EventArgs)
 If  Request.Form("Email") <> "" Then
   Dim objMail As New MailMessage()
   objMail.From = Request.Form(SENDING ADDRESS)
   objMail.To = "EMAIL ADRESSES TO"
   objMail.Subject = "An order has been submitted"
   objMail.Body = Request.Form("txtClientName")
   objMail.BodyFormat = MailFormat.Text
   SmtpMail.SmtpServer = "SMTP SERVER"
   SmtpMail.Send(objMail)

 End If
End Sub

</script>  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bhnmiCommented:
Oops, tried to take out most of my code but some got stuck in there. Just a general idea.
0
georgem767Author Commented:
I used your code and I get this error message:

The server rejected the sender address. The server response was: 530 5.7.0 Must issue a STARTTLS command first s33sm3941426hub.32
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

bhnmiCommented:
gmail will not let you just relay through the smtp server. You would be better off installing a smtp server on the server running the application and use it for a relay.

With gmail you will have to use a secure connection and authenticate to relay through it.
0
georgem767Author Commented:
so if i setup smtp on my webserver, can I use "localhost" for my smtp server?
0
bhnmiCommented:
yup.
0
georgem767Author Commented:
BEAUTIFUL IT WORKS!

Just one or two more things.  

--how can i send to more than one email address?  
--how can i put more than only the client's name in the body?  I was hoping I could do something like

[txtClientName.text] has submitted an order!  click here to view.  



0
georgem767Author Commented:
Sorry, one more thing...

on my other form, the code is contained in a separate page (page.aspx.vb)

where would i include the <%@ improt namespace..... %> tag in that instance?  it doesnt seem to want me to do it at the top of the code page.
0
bhnmiCommented:
Show me the code you have.
0
georgem767Author Commented:
Here's the code I'm using on the first form.  (the vb is in the same page as the HTML)
I gave it a shot sending the emails with a semicolon between them and it worked.

I can't send you the code of the other form.  Its a wizard and its about 20 steps long--it would be way too much.  The vb code is on a separate page (page.aspx.vb)



<%@Import Namespace="system.web.mail" %>
<script runat="server">
    Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
 
    End Sub
    
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        SqlDataSource1.Insert()
        ordernumberform.Visible = True
        
        Dim objMail As New MailMessage()
        objMail.From = "dru@sendclaim.com"
        objMail.To = "webmaster@sendclaim.com; maryb@sendclaim.com"
        objMail.Subject = "An order has been submitted"
        objMail.Body = Request.Form("txtresellercompany")
        objMail.BodyFormat = MailFormat.Text
        SmtpMail.SmtpServer = "localhost"
        SmtpMail.Send(objMail)
    End Sub
 
    Protected Sub btnlookup_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Redirect("find_order.aspx", True)
    End Sub
</script>

Open in new window

0
bhnmiCommented:
So its working now?
0
georgem767Author Commented:
The code of the first form (what i showed you above) is working fine.  I would just like to append additional text after request.form("txtresellercompany").

and on the second form i want to use, all of my VB is on a seperate file (page.aspx.vb).  I do not know where to put the import namespace code when the VB is on a page all by itself.  does it still go way at the top? or should i leave out the <%@  and %> ?
0
bhnmiCommented:
Hmm, I am not the best programmer... so I use trail and error. I would put it at the top after you define the script language. If not just move it around till it works. I am assuming you have a dev box that will not effect production.
0
georgem767Author Commented:
okay i got that, i had to use "imports system.web.mail"

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.