Alright I give up on my hosting. Found a server with my college that supports .aspx pages.
Here is where a working version of the page is:
Chris Bornhoft - Email System. Of course no email will work because as you see in the code below the SMTP server I used is called mailserver.com which doesn't exist. But I have used it with my own site's email and yahoo's email and they both work.
Here is the ASP.NET code:
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="email.aspx.cs" Inherits="extra_email" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Chris Bornhoft - Email System</title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
font-family: Arial;
}
.style3
{
font-family: Arial;
width: 177px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3 class="style2">Email System</h3>
<table class="style1">
<tr>
<td class="style3" valign="top">
<span class="style2">Select a Message Type:</span> </td>
<td class="style2">
<asp:DropDownList ID="ddl_type" runat="server" AutoPostBack="True"
onselectedindexchanged="ddl_type_SelectedIndexChanged">
<asp:ListItem Value="Email">Email</asp:ListItem>
<asp:ListItem Value="Text">Text</asp:ListItem>
</asp:DropDownList>
<br />
<br />
</td>
</tr>
<tr>
<td class="style3" valign="top">
<asp:Label ID="lbl_to" runat="server" Text="To:"></asp:Label>
</td>
<td class="style2">
<asp:TextBox ID="tbx_to" runat="server" Width="200px"></asp:TextBox>
<br />
</td>
</tr>
<tr>
<td class="style3" valign="top">
<asp:Label ID="lbl_user" runat="server" Text="User:"></asp:Label>
</td>
<td class="style2">
<asp:TextBox ID="tbx_user" runat="server" Width="200px"></asp:TextBox>
<br />
</td>
</tr>
<tr>
<td class="style3" valign="top">
<asp:Label ID="lbl_pass" runat="server" Text="Password:"></asp:Label>
</td>
<td class="style2">
<asp:TextBox ID="tbx_pass" runat="server" Width="200px"></asp:TextBox>
<br />
</td>
</tr>
<tr>
<td class="style3" valign="top">
<asp:Label ID="lbl_cc" runat="server" Text="CC:"></asp:Label>
</td>
<td class="style2">
<asp:TextBox ID="tbx_cc" runat="server" Width="200px"></asp:TextBox>
<br />
<br />
<br />
</td>
</tr>
<tr>
<td class="style3" valign="top">
Subject:</td>
<td class="style2">
<asp:TextBox ID="tbx_subject" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3" valign="top">
Message:</td>
<td class="style2">
<asp:TextBox ID="tbx_message" runat="server" Height="300px" Width="600px"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
</table>
<asp:Button ID="btn_send" runat="server" Text="Send" Width="80px" onclick="btn_send_Click"/>
<br />
<p>
<asp:Label ID="lbl_error" runat="server" style="font-family: Arial"></asp:Label>
</p>
</form>
</body>
</html>
Here is the server side C# code:
Code:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Net.Mail;
using System.Collections;
public partial class extra_email : System.Web.UI.Page
{
protected void ddl_type_SelectedIndexChanged(object sender, EventArgs e)
{
if(ddl_type.SelectedValue == "Email")
{
lbl_to.Text = "To:";
lbl_user.Text = "User:";
lbl_pass.Visible = true;
tbx_pass.Visible = true;
lbl_cc.Visible = true;
tbx_cc.Visible = true;
}
else if (ddl_type.SelectedValue == "Text")
{
lbl_to.Text = "Phone Number:";
lbl_user.Text = "Your Phone Number:";
lbl_pass.Visible = false;
tbx_pass.Visible = false;
lbl_cc.Visible = false;
tbx_cc.Visible = false;
}
}
protected void btn_send_Click(object sender, EventArgs e)
{
string to = tbx_to.Text;
string from = tbx_user.Text + "@mailserver.com";
string user = tbx_user.Text;
string pass = tbx_pass.Text;
string cc = tbx_cc.Text;
string subject = tbx_subject.Text;
string message = tbx_message.Text;
MailAddress From = new MailAddress(from);
MailAddress To = new MailAddress(to);
MailMessage Mail = new MailMessage(From, To);
//NetworkCredential UserInfo = new NetworkCredential(user, pass);
Mail.Subject = subject;
Mail.Body = message;
SmtpClient MailServer = new SmtpClient("mailserver.com", 465);
/*
MailServer.EnableSsl = true;
MailServer.UseDefaultCredentials = false;
MailServer.Credentials = UserInfo;
*/
if(ddl_type.SelectedValue == "Email")
{
if (cc.Length > 0)
{
MailAddress c = new MailAddress(cc);
Mail.CC.Add(c);
}
}
else
{
SmtpClient TextServer = new SmtpClient("textserver.com");
try
{
TextServer.Send(Mail);
lbl_error.Text = "Message successfully sent.";
}
catch (Exception ex)
{
lbl_error.Text = ex.ToString();
}
}
try
{
MailServer.Send(Mail);
lbl_error.Text = "Mail successfully sent.";
}
catch (Exception ex)
{
lbl_error.Text = ex.ToString();
}
}
}
I did not implement any textbox validation so if you leave an email box blank the page will crash. If you need validation I can easily assist you with it.
Hope it helps. If you have any questions on what something means feel free to ask.