Created
April 2, 2012 14:29
-
-
Save reverentgeek/2283845 to your computer and use it in GitHub Desktop.
Test Mail with C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" %> | |
<%@ Import namespace="System.Net.Mail" %> | |
<script runat="server"> | |
protected void SubmitClick(object sender, EventArgs e) | |
{ | |
MailMessage mail = new MailMessage(); | |
mail.From = new MailAddress(txtFrom.Text); | |
mail.To.Add(txtTo.Text); | |
mail.Subject = txtSubject.Text; | |
mail.Body = txtBody.Text; | |
SmtpClient smtp = new SmtpClient("127.0.0.1"); | |
smtp.Send(mail); | |
lblResult.Text = "Message sent"; | |
} | |
</script> | |
<!doctype html> | |
<html> | |
<head> | |
<title>Mail Test</title> | |
<style type="text/css"> | |
body { font-family: Arial; } | |
</style> | |
</head> | |
<body> | |
<form runat="server"> | |
<h1>Mail Test</h1> | |
<p><asp:Label ID="lblResult" runat="server" /></p> | |
<table cellpadding="3" cellspacing="0" border="0"> | |
<tr> | |
<td align="right"><label for="<%=txtTo.ClientID%>">To:</label></td> | |
<td><asp:TextBox ID="txtTo" runat="server" /></td> | |
</tr> | |
<tr> | |
<td align="right"><label for="<%=txtFrom.ClientID%>">From:</label></td> | |
<td><asp:TextBox ID="txtFrom" runat="server" /></td> | |
</tr> | |
<tr> | |
<td align="right"><label for="<%=txtSubject.ClientID%>">Subject:</label></td> | |
<td><asp:TextBox ID="txtSubject" runat="server" /></td> | |
</tr> | |
<tr> | |
<td align="right"><label for="<%=txtBody.ClientID%>">Body:</label></td> | |
<td><asp:TextBox ID="txtBody" runat="server" TextMode="Multiline" /></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td><asp:Button ID="Submit" runat="server" Text="Send" OnClick="SubmitClick" /> | |
</tr> | |
</table> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment