Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic EMail when Database is modified

Status
Not open for further replies.

isthisthingon

IS-IT--Management
May 17, 2005
65
US
I am new to this, so please be specific.

I have set up a secure portion of our website accessable by logins. I have setup a form for users to register a login for themselves. How would I set it up to automatically email the registration details of users once the asp form inserts the data into the database?

Thanks for all help .. .. I know someone has a simple solution to this need that I am having trouble with.

Also, my form checks for blank email addresses using the following code:

if strEmail = "" then
blnValid = False
strValid = strValid & "<table border=""0"" width=""302"" cellspacing=""0"" cellpadding=""0"" height=""22"">" & vbCrLf &_
"<tr>" & vbCrLf &_
"<td width=""300"" height=""22""><p align=""left""><font face=""Verdana"" size=""2"" color=""#000080""># Please Enter Your E-Mail ID.</p></td>" & vbCrLf &_
"</tr>" & vbCrLf &_
"</table>"
end if

How would I validate for an email address containing "@ourdomainname.org"

Thanks!!!!
 
Add to the email whatever you want.
Code:
    Sub runTest(ByVal sender As Object, ByVal e As EventArgs)
        Dim strEmail As String = email.Text
        If Not strEmail Like "*@test.com" Then
            message.Text = "Error!"
        Else
            message.Text = "Success!"
            sendEmail(strEmail)
        End If
    End Sub

    Sub sendEmail(ByVal email As String)
        Dim genEmail As New System.Web.Mail.MailMessage
        genEmail.From = "me@mydomain.com"
        genEmail.To = email
        genEmail.Subject = "Request Details"
        genEmail.BodyFormat = Mail.MailFormat.Html
        genEmail.Body = "Thank you for your request.<br>"
        genEmail.Body &= "<b>Requestor</b>: " & myTextBox.Text & "<br>"
        genEmail.Body &= "<b>Name</b>: " & myNameBox.Text & "<br>"
        genEmail.Body &= "<b>Keep Adding</b>: " & whateveryouwant.Text & "<br>"

        System.Web.Mail.SmtpMail.SmtpServer = "mySMTPServerHere"
        System.Web.Mail.SmtpMail.Send(genEmail)
    End Sub
 
How would I validate for an email address containing "@ourdomainname.org"
If it's as simple as checking whether that domain exists in the email, have a look at IndexOf. Otherwise, use a regular expression.

Also, note that the solution above is for version 1.1 of the framework. You'll have to use the System.Net.Mail namespace if you are using version 2.0 and the syntax will be slightly different.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks, but I'm still having trouble.

how would I change this to check for "@ourdoamin.net"

if strEmail = "" then
blnValid = False
strValid = strValid & "<table border=""0"" width=""302"" cellspacing=""0"" cellpadding=""0"" height=""22"">" & vbCrLf &_
"<tr>" & vbCrLf &_
"<td width=""300"" height=""22""><p align=""left""><font face=""Verdana"" size=""2"" color=""#000080""># Please Enter Your E-Mail ID.</p></td>" & vbCrLf &_
"</tr>" & vbCrLf &_
"</table>"
end if
 
Did you look up the IndexOf function of a String?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Ok, if thats the way you need to go, do as such.
If you are trying to prevent errors, i suggest using the Trim function (built in) to clear whitespace so someone cannot just hit the spacebar and submit.

Code:
        If [b]Trim(strEmail)[/b] = "" Or [b]strEmail.IndexOf("@ourdomain.net") < 1[/b] Then
            blnValid = False
            strValid = strValid & "<table border=""0"" width=""302"" cellspacing=""0"" cellpadding=""0"" height=""22"">" & vbCrLf & _
             "<tr>" & vbCrLf & _
             "<td width=""300"" height=""22""><p align=""left""><font face=""Verdana"" size=""2"" color=""#000080""># Please Enter Your E-Mail ID.</p></td>" & vbCrLf & _
             "</tr>" & vbCrLf & _
             "</table>"
        End If

we are assuming you only want users @ourdomain.net to submit the form right?
 
yes, I only want people with an email address in our domain to be able to register. I know for now this does not prevent someone from just making up an address@ourdomain. I'll be working on the functionality to send an email to all users upon registration with a link back to the database to register their account. Once I tackle this, I will do that. I am very new to this and taking baby steps. Thanks sooo much for the code, I will try it later today.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top