Cheap Windows ASP.NET Hosting Tutorial – How to Sending Email from ASP.NET 5

ByAlexia Pamelov

Cheap Windows ASP.NET Hosting Tutorial – How to Sending Email from ASP.NET 5

5/5 - (1 vote) | Best and cheap ASP.NET 5 hosting. In this post I will explain about how to send email from ASP.NET. Below is sample code showing how to send email from ASP.Net 5 (currently in beta as of this posting) using C#. With this code I am assuming that the server already has a local SMTP service installed, so I use “localhost” to relay the email.

Here is the SendMail.aspx page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SendMail.aspx.cs" Inherits="SendMail" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        Message to:
        <asp:TextBox ID="txtTo" runat="server"></asp:TextBox>
        <br />
        Message from:
        <asp:TextBox ID="txtFrom" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="txtSubject" runat="server"></asp:TextBox>
        <br />
        Message Body:
        <br />
        <asp:TextBox ID="txtBody" runat="server" Height="171px" TextMode="MultiLine"
        <br />
        <asp:Button ID="Btn_SendMail" runat="server" onclick="Btn_SendMail_Click"
            Text="Send Email" />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

 Here is the source code of the SendMail.aspx.cs page:

Best OFFER Cheap ASP.NET 5 Hosting ! Click Here

using System;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class SendMail : System.Web.UI.Page

    protected void Btn_SendMail_Click(object sender, EventArgs e)
        MailMessage mailObj = new MailMessage(
            txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);
        SmtpClient SMTPServer = new SmtpClient("localhost");
            catch (Exception ex)
            Label1.Text = ex.ToString();

I hope this article helpful for you.  Happy coding 🙂

About the Author

Alexia Pamelov administrator

    Leave a Reply