problem getting mail working

Discussion in 'ASP.NET 2.0' started by mdean99, Oct 11, 2011.

  1. hi
    what is wrong please with the following code which is supposed to send an email from a feedback form.
    Thanks

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ Page Language="VB" AutoEventWireup="false" %>
    <%@ Import Namespace="System.Net.Mail" %>
    +++++++++++++

    <asp:textbox Runat="server" id="Name" Width="400" ></asp:textbox>
    <asp:textbox id="Email" Width="400" Runat="server"></asp:textbox>
    <asp:textbox id="Subject" Width="400" Runat="server"></asp:textbox>
    <asp:textbox id="Message" Width="100%" Runat="server" Height="140" TextMode="MultiLine" MaxLength="400"></asp:textbox>

    <asp:button id="btnSendmail" Runat="server" Text="Send email" OnClick="btnSendmail" Font-Bold="true"></asp:button>


    code behind

    Partial Class send_MailMessage
    Inherits System.Web.UI.Page

    Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
    Dim name As String = ""
    Dim mailTo As String = ""
    Dim mailSubject As String = ""
    Dim mailBody As String = ""
    Dim myMail As New System.Net.Mail.MailMessage("[email protected]", mailTo, mailSubject, mailBody)
    myMail.IsBodyHtml = True

    Try
    Dim c As New System.Net.Mail.SmtpClient()
    c.Send(myMail)
    mailSubject = ""
    mailBody = ""
    Catch myEx As System.Net.Mail.SmtpException
    System.Diagnostics.Debug.WriteLine("Error sending mail: " & myEx.Message)
    Throw myEx
    Finally
    myMail = Nothing
    End Try

    End Sub
    End Class
     
  2. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

Share This Page