Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2008, 02:36 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Web Form Email Job Problem

I have a web form that pulls data entered by the user, and then sends out an email to the user and an email group based on the category selected by the user. The groups used for the categories are stored within an XML doc. I'm able to parse the XML doc without a problem. I know this because I assigned the email variable to a label on the page, and I can see the result after the form is submitted.

But when I try to apply that same email address variable from that XML parse into the email job within the code file, I receive the following error:
The specified string is not in the form required for an e-mail address.

I've included my code below. If anyone could let me know what steps I'm missing, that would be great. Thanks.

test.aspx
Code:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" CodeFile="test.aspx.vb" Inherits="feedback_test" AutoEventWireup="true" title="Feedback Form - TEST" %>
<asp:content id="Content1" contentplaceholderid="ContentPlaceHolder1" runat="server">
    <% If Not Page.IsPostBack Then %>
    <form name="formFeedback" action="" method="post" runat="server">
        <asp:ValidationSummary ID="valSummary" runat="server"
            HeaderText="You must fix the following form entries:"
            Font-Names="verdana" 
            Font-Size="10pt"
            Font-Bold="True" 
        />
        <br />
        <table class="tableborder_black" width="98%" id="Feedback Form">
            <tbody>
                <tr class="tablecell_black">
                    <th scope="col" colspan="2">Feedback Form</th>
                </tr>
                <tr>
                    <td class="tablecell1" align="right" valign="top">Category</td>
                    <td class="tablecell3">
                        <asp:DropDownList id="selectCategory" runat="server">
                            <asp:ListItem Value="gen" Text="General" Selected="True" />
                            <asp:ListItem Value="cat1" Text="Category 1" />
                            <asp:ListItem Value="cat2" Text="Category 2" />
                            <asp:ListItem Value="cat3" Text="Category 3" />
                        </asp:DropDownList>
                    </td>
                </tr>

                <tr>
                    <td class="tablecell1" align="right" valign="top">Email Address</td>
                    <td class="tablecell3"><asp:Textbox id="txtEmailAddress" columns="20" runat="server" />
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" ControlToValidate="txtEmailAddress"
                            ErrorMessage="Email must be valid (Format: you@domain.com)." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                    </td>
                </tr>
                <tr>
                    <td class="tablecell1" align="right" valign="top" style="height: 50px">Comments</td>
                    <td class="tablecell3" style="height: 50px">
                        <asp:TextBox ID="txtComments" Columns="40" Rows="4" runat="server" Height="60px" TextMode="MultiLine"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtComments"
                            ErrorMessage="Must enter comments to complete this form." Display="Dynamic"></asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator8" runat="server" ControlToValidate="txtComments"
                            ErrorMessage="Must enter between 5 and 1000 characters." ValidationExpression="^[a-zA-Z-0-9]{5,1000}$" Display="Dynamic"></asp:RegularExpressionValidator>
                    </td>
                </tr>
                <tr class="tablecell_black">
                    <td scope="col" colspan="2" align="center">
                        <asp:HiddenField ID="hfDateTime" runat="server" />
                        <input id="btnReset" type="Reset" runat="server">
                        <asp:Button ID="btnSubmit" Text="Submit" OnClick="SubmitBtn_Click" runat="server" />
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
        <br /><br />

        <strong>lblContactsTitle: </strong><asp:label id="lblContactsTitle" runat="server" /><br />
        <strong>lblContactsEmail: </strong><asp:label id="lblContactsEmail" runat="server" /><br />
        <strong>lblCategory: </strong><asp:label id="lblCategory" runat="server" /><br />
        <strong>lblEmailAddress: </strong><asp:label id="lblEmailAddress" runat="server" /><br />
        <strong>lblComments: </strong><asp:label id="lblComments" runat="server" /><br />
        <% Else %>
        <asp:label id="lblErrorMsg" runat="server" /><br />
        <% End If %>
</asp:content>
test.aspx.vb
Code:
Partial Class feedback_test
    Inherits System.Web.UI.Page

    Dim strSiteDomain As String = "/mysite"

    Sub SubmitBtn_Click(ByVal Sender As Object, ByVal E As EventArgs)
        'Declare form variables
        Dim category_form As String = selectCategory.SelectedItem.Value
        Dim email_form As String = txtEmailAddress.Text
        Dim comments_form As String = txtComments.Text

        'Assign date variables
        Dim dtCurrDate As DateTime = DateTime.Now 'Assign current date
        Dim strDateTimeISO As String = dtCurrDate.ToString("s") 'ISO format
        hfDateTime.Value = strDateTimeISO

        'Assign labels
        lblCategory.Text = category_form
        lblEmailAddress.Text = email_form
        lblComments.Text = comments_form

        If Page.IsValid Then
            Try
                'Pull group members by selected category
                Dim objEmailGroup As Object = False
                Dim strXMLPath_contacts As String, strXSLPath_contacts As String
                strXMLPath_contacts = strSiteDomain & "/help/docs/xml/contacts.xml" 'xml doc
                strXSLPath_contacts = strSiteDomain & "/help/docs/xslt/contacts.xsl" 'xsl doc

                'Load MainContent XML file internal_links.xml and assign page properties
                Dim strContactsTitle As String = Nothing, strContactsEmail As String = Nothing
                Dim contacts_xmld As XmlDocument
                Dim contacts_nodelist As XmlNodeList
                Dim xml_node As XmlNode
                'Create the XML Document
                contacts_xmld = New XmlDocument()
                'Load the Xml file
                contacts_xmld.Load(MapPath(strSiteDomain & "/help/docs/xml/contacts.xml"))

                'Get the list of name nodes
                contacts_nodelist = contacts_xmld.SelectNodes("/contacts/dept_div[@id = '" & category_form & "']")
                'Response.Write(contacts_nodelist) 'TEST

                'Loop through the nodes
                For Each xml_node In contacts_nodelist

                    'Pull XML nodes
                    strContactsTitle = xml_node.Item("title").InnerText
                    strContactsEmail = xml_node.Item("email_contacts").InnerText

                    lblContactsTitle.Text = strContactsTitle
                    lblContactsEmail.Text = strContactsEmail

                Next 'end loop

                'Email job to group members
                Dim mail_group As New System.Net.Mail.MailMessage(email_form, strContactsEmail, "Feedback Form", "The following feedback was submitted to your department:<br /><br/ ><strong>Category: </strong>" & category_form & "<br /><strong>Comments: </strong>" & comments_form & "")
                Dim mail_user As New System.Net.Mail.MailMessage("webmaster@mysite.com", email_form, "Feedback Form", "Thank you for submitting feedback through our feedback form. If requested, someone from our staff will be in contact with you withing 2-3 business days.<br /><br />Webmaster")

                Response.Write("objEmailGroup = True<br />")

                'strContactsEmail
                'email_form = user's email address

                mail_group.BodyEncoding = System.Text.Encoding.UTF8
                mail_group.IsBodyHtml = True
                mail_user.BodyEncoding = System.Text.Encoding.UTF8
                mail_user.IsBodyHtml = True

                Dim smtpUser As String = "USERNAME"
                Dim smtpPassword As String = "PASSWORD"
                Dim smtpServer As String = "EMAILSERVERNAME"

                Dim smtp As New Net.Mail.SmtpClient()

                With smtp
                    If smtpUser.Length > 0 Then
                        .Host = smtpServer
                        .Port = 25
                        .Credentials = New System.Net.NetworkCredential(smtpUser, smtpPassword)
                    End If
                End With

                'Email job to group
                smtp.Send(mail_group)

                'Email job to user for confirmation (if email is not empty)
                If email_form <> "" Then
                    smtp.Send(mail_user)
                End If

            Catch
                lblErrorMsg.Text = "There was a problem while submitting this form. Please contact the <a href='mailto:webmaster@mysite.com'>Webmaster</a>."
            End Try
        End If
    End Sub

End Class
KWilliams
 
Old June 23rd, 2008, 08:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

What do you see on your page? is the string "well formed", are every address separate correctly, with a "," (or a ";", never remember wich one) in the middle?

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old June 24th, 2008, 02:27 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After further research, I found out that I need to use commas (,) instead of semicolons (;). Once I did that, it worked great. Thanks for your help.:)

KWilliams





Similar Threads
Thread Thread Starter Forum Replies Last Post
email- from web form pzmrcd .NET Framework 2.0 1 July 24th, 2007 11:29 AM
ASP classic Form to Email problem melkin Classic ASP Basics 0 April 19th, 2007 10:28 AM
Please Help: CDONTs - Form to Email problem nancy Classic ASP Basics 18 October 29th, 2004 05:35 PM
problem in web email encoding yoord ADO.NET 1 June 29th, 2004 10:58 PM
web form control problem myavi ADO.NET 1 June 5th, 2004 12:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.