Sending mail from a Web page (C#) : Email « Development « ASP.NET Tutorial






<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Net.Mail.MailMessage message =
            new System.Net.Mail.MailMessage("webmaster@a.org", "webmaster@a.org");
        message.Subject = "Sending Mail with ASP.NET 2.0";
        message.Body =
            "This is a sample email which demonstrates sending email using ASP.NET 2.0";
        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("localhost");
        smtp.Send(message);

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>








9.14.Email
9.14.1.Send email from your page (C#)
9.14.2.Sending mail from a Web page (VB)
9.14.3.Sending mail from a Web page (C#)
9.14.4.Send an email out (VB.net)
9.14.5.The MailDefinition class uses the email server configured by the smtp element in the web configuration file.