form to email Problems! --update: I got it to work, no help needed, ignore this post, thanks

Discussion in 'ASP.NET 2.0' started by vandiermen, Dec 21, 2006.

  1. I asked the following question before I followed theses instructions and got a form to be sent through my email (thank god![​IMG])
    http://aspnet.4guysfromrolla.com/articles/072606-1.aspx
    __________________________________________________________________


    The code that work for me is as follows, and that may work for anyone using asp.net 2.0 as long as they also "Configure SMTP e-mail settings" in their "ASP.Net Web Application Administration Tool" with "visual web developer 2005"



    <%@ Page Language="VB" %> <%@ Import Namespace="System.Net.Mail" %></o:p>
    </o:p>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></o:p>
    </o:p>
    <script runat="server"></o:p>
    </o:p>
    </o:p>
    Protected Sub SendEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendEmail.Click</o:p>
    '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS</o:p>
    Const ToAddress As String = "[email protected]"</o:p>
    </o:p>
    '(1) Create the MailMessage instance</o:p>
    Dim mm As New MailMessage(UsersEmail.Text, ToAddress)</o:p>
    </o:p>
    '(2) Assign the MailMessage's properties</o:p>
    mm.Subject = Subject.Text</o:p>
    mm.Body = Body.Text</o:p>
    mm.IsBodyHtml = False</o:p>
    </o:p>
    '(3) Create the SmtpClient object</o:p>
    Dim smtp As New SmtpClient</o:p>
    </o:p>
    '(4) Send the MailMessage (will use the Web.config settings)</o:p>
    smtp.Send(mm)</o:p>
    End Sub</o:p>
    </o:p>
    </o:p>
    </script></o:p>
    </o:p>
    <html xmlns="http://www.w3.org/1999/xhtml" ></o:p>
    <head runat="server"></o:p>
    <title>Untitled Page</title></o:p>
    </head></o:p>
    </o:p>
    <form id="form1" runat="server"></o:p>
    <div></o:p>
    </o:p>
    <table border="0"></o:p>
    <tr></o:p>
    <td>Your Email:</b></td></o:p>
    <td><asp:TextBox runat="server" ID="UsersEmail" Columns="30"></asp:TextBox></td></o:p>
    </tr></o:p>
    <tr></o:p>
    <td>Subject:</b></td></o:p>
    <td><asp:TextBox runat="server" ID="Subject" Columns="30"></asp:TextBox></td></o:p>
    </tr></o:p>
    <tr></o:p>
    <td colspan="2"></o:p>
    Body:</b></o:p>
    <asp:TextBox runat="server" ID="Body" TextMode="MultiLine" Columns="55" Rows="10"></asp:TextBox></o:p>
    </td></o:p>
    </tr></o:p>
    <tr></o:p>
    <td colspan="2" align="center"></o:p>
    <asp:Button runat="server" ID="SendEmail" Text="Send Feedback" /></o:p>
    </td></o:p>
    </tr></o:p>
    </table> </o:p>
    </o:p>
    </o:p>
    </div></o:p>
    </form></o:p>
    </body></o:p>
    </html>


    ______________________________________________________________


    My original question: </o:p>


    I am trying to make a form that?s sends the information to my email address, and I?m having problems, and I feel stupid? (I hear its easy but I?m not having any luck?)

    I have checked out heaps of walkthroughs on the matter, and I am using this one, and I like this one the best: http://www.sitepoint.com/article/sending-web-email-asp-net

    I have tried to use the example scrip on the above link and came up with heaps errors, so I tried to make the simplest form I could, here is what I came up with:


    <%@ Page Language="VB" %> <%@ Import Namespace="System.Web.Mail" %></o:p>
    </o:p>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></o:p>
    </o:p>
    <script runat="server"></o:p>
    </o:p>
    Dim objMail As New MailMessage()</o:p>
    objMail.From = "[email protected]"</o:p>
    objMail.To = "[email protected]"</o:p>
    objMail.BodyFormat = MailFormat.Html</o:p>
    objMail.Subject = "My first ASP.NET email"</o:p>
    objMail.Body = "This is my first email sent via ASP.NET. :)"</o:p>
    </o:p>
    SmtpMail.Send(objMail)</o:p>
    </o:p>

    </script></o:p>
    </o:p>
    <html xmlns="http://www.w3.org/1999/xhtml" ></o:p>
    <head runat="server"></o:p>
    <title>Untitled Page</title></o:p>
    </head></o:p>
    </o:p>
    <form id="form1" runat="server"></o:p>
    <div></o:p>
    </o:p>
    I HAVE NOT TRIED TO ADD TOO MUCH HERE, AS THE TOP SECTION IS COMING UP WITH ERRORS AND I AM SURE IS MISSING BITS

    I WOULD LOVE SOME GOOD CODE FOR THIS WHOLE THING


    If you were wandering what msresume means, I am making a site for My Supper Resume in my country</o:p>
    <td class="main"><input type="Submit" </o:p>
    id="btnSubmit" OnServerClick="btn_Click" value="Send" </o:p>
    runat="server" /></td> </o:p>
    </div></o:p>
    </form></o:p>
    </body></o:p>
    </html>




    This is the SMTP connection in my web.config:

    I would have used my discountasp.net smtp server but its not working, and my smtpout.secureserver.net (SMTP) definitely is working

    <system.net></o:p>
    <mailSettings></o:p>
    <smtp from="[email protected]"></o:p>
    <network host="smtpout.secureserver.net" password="**********" port="80" userName="[email protected]"/></o:p>
    </smtp></o:p>
    </mailSettings></o:p>
    </system.net></o:p>
    </o:p>


    This is the first error message I come up with, but I got a feeling theresmore to come..

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30188: Declaration expected.

    Source Error:







    Code:
    Line 6:  
    Line 7:      Dim objMail As New MailMessage()
    Line 8:      objMail.From = "[email protected]"
    Line 9:      objMail.To = "[email protected]"
    Line 10:     objMail.BodyFormat = MailFormat.Html
    Source File: C:\Documents and Settings\admin\My Documents\Visual Studio 2005\WebSites\formEmail21\Default2.aspx Line: 8



    </o:p>


    I WOULD LOVE SOME CODE THAT WILL WORK FOR ME



    Post Edited (vandiermen) : 12/21/2006 5:30:01 PM GMT
     
  2. OK to start with maybe there's a problem with using version 1.1 code with a version 2.0 site </o:p>
    </o:p>
    I just saw on the site I'm getting the code from (http://www.sitepoint.com/article/sending-web-email-asp-net ) that it is code for v1.1, and I usually use 2.0 and maybe it incompatible with my web.config or something????
     
  3. I have been testing this form on my local computer using visual web developer debugger, I have not uploaded it, so I don?t know how visual web developer determines whether it?s a asp.net 1.1 site or asp.net 2.0
     
  4. This would be the working web.config for ASP.NET 2.0 smtp:


    <configuration>
    <appSettings/>
    <connectionStrings/>
    <system.net>
    <mailSettings>
    <smtp>
    <network host="localhost" port="25" />
    </smtp>
    </mailSettings>
    </system.net>
    <system.web>
    <customErrors mode="Off"/>
    <compilation debug="false">
    </compilation>
    </system.web>
    </configuration>

    The inherits for your code page:
    Imports System.Net.Mail
    Imports System.Net
     
  5. 2 cool [​IMG] (Good job.)
     

Share This Page