Introduction
In this article, you will learn how to create communications applications, like an email applications, using C#, ASP.NET, and Visual Studio 2015 Update 3.
Requirements
- Visual Studio 2015 Update 3
- ASP.NET 4.5.2
If you want to develop communications applications, you should follow the steps, mentioned below.
Step 1
Open Visual Studio 2015 Update 3, go to the File >> New >> Project. Or, use the shortcut key - "Ctrl+Shift +N".
Step 2
Now, select Visual C# >> Web >> ASP.NET Web Application. Finally, click "OK" button.
Step 3
Here, you can select the template for your ASP.NET application. We are choosing "Empty" here. Now, click OK button.
Step 4
Now, open the project and look for the Solution Explorer .
Step 5
Here, open the default .aspx. If you want a Web form, you can add the page (Web form) Add+New item (Ctrl+Shift+A).
Step 6
Now, we can build the design using drag and drop method. Open the toolbox, if you want some options there. It should be like the textbox, label, and so on.
Step 7
Here is the default.aspx code.
Default.aspx code
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="communi.aspx.cs" Inherits="communication.communi" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
-
- <head runat="server">
- <title></title>
- <link href="style.css" rel="stylesheet" type="text/css" />
- <style type="text/css">
- .auto-style1 {
- width: 100%;
- }
- </style>
- </head>
-
- <body>
- <form id="form1" runat="server">
- <div id="from">
- <h1>ASP.Net COMMUNICATION APPLICATION</h1>
- </div>
- <div id="fromone">
- <table class="auto-style1">
- <tr>
- <td>
- <asp:Label ID="Label1" runat="server" Text="To(E-Mail Address)"></asp:Label>
- </td>
- <td>
- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <asp:Label ID="Label" runat="server" Text="Subject"></asp:Label>
- </td>
- <td>
- <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
- </td>
- </tr>
- </table> <br />
- <asp:Label ID="Label2" runat="server" Text="Message"></asp:Label><br />
- <asp:TextBox ID="TextBox3" TextMode="MultiLine" runat="server" Height="82px" Width="357px"></asp:TextBox><br />
- <asp:Button ID="Button1" runat="server" Text="SEND" /><br />
- <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
- </div>
- </form>
- </body>
-
- </html>
Step 8
Now, first of all, declare the header file, because this project is based on SMTP (Simple Mail Transfer Protocol).
using System.Net.Mail;
Here, fill in the C# code.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Net.Mail;
- namespace communication {
- public partial class communi: System.Web.UI.Page {
- protected void Page_Load(object sender, EventArgs e) {}
- protected void Button1_Click(object sender, EventArgs e) {
- SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
- SmtpServer.Port = 587;
- SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "muthu@123");
- }
- }
- }
Step 9
Here, you can see the output.
Step 10
Afterwards, add the File upload option in the Communication application.
Now, add the FileUpload control. Make use of the drag method.
Step 11
Here, you can see the C# code.
Step 12
Now, you can see default.aspx code.
<asp:FileUpload ID="FileUpload1" runat="server" />
Step 13
Now, you have the option of mailing with file upload feature.
The file is uploaded and you can see the final output.