ASP.Net/Network/MailMessage

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Send out MailMessage

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Mail" %>
<script runat="server">    
    void Button1_Click(Object sender, EventArgs e) {
    MailMessage EMail = new MailMessage();
    EMail.To = "d@s.ru";
    EMail.From = "r@a.ru";
    EMail.Cc = "s@a.ru";
    EMail.Subject = "Test Email";
    EMail.Body = "Here is the body of our email";
    SmtpMail.SmtpServer = "localhost";
    try{
      SmtpMail.Send(EMail);
    }
    catch (Exception exc){
      Response.Write("Send failure: " + exc.ToString());
    }
    }
</script>
<html>
  <head>
  </head>
  <body>
    <form runat="server">
      <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Send Email" Width="103px"></asp:Button>
      <!-- Insert content here -->
    </form>
  </body>
</html>