<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net.Mail" %>
<head runat="server">
<title>Senden einer Nachricht</title>
<script runat="server">
string Mailserver = ""; // mail.fiala.cc
string Username = ""; // franz@fiala.cc
string Passwort = ""; // Passwort
string strFrom = "franz@fiala.cc";
string strTo = "";
string strCc = "";
string strBcc = "";
string strSubject = "Betrifft";
string strBody = "Nachrichtentext";
void Page_Load(object sender, EventArgs e)
{
if (Request.IsLocal)
{
string strCmdFrom = Request.Params["from"]; if (!string.IsNullOrEmpty(strCmdFrom)) strFrom = strCmdFrom;
string strCmdTo = Request.Params["to"]; if (!string.IsNullOrEmpty(strCmdTo)) strTo = strCmdTo;
string strCmdSubject = Request.Params["subj"]; if (!string.IsNullOrEmpty(strCmdSubject)) strSubject = strCmdSubject;
string strCmdBody = Request.Params["body"]; if (!string.IsNullOrEmpty(strCmdBody)) strBody = strCmdBody;
if (strTo != "")
{
Panel_MailDialog.Visible = false;
SendMailMessage(strFrom, strTo, strBcc, strCc, strSubject, strBody);
}
}
}
void Button_Send_Click(object sender, EventArgs e)
{
SendMailMessage(strFrom, TextBox_Email.Text, "", "", "Betrifft: " + TextBox_Subject.Text, "Nachricht: " + TextBox_Message.Text);
}
/// <summary>
/// Sends an mail message
/// </summary>
/// <param name="from">Sender address</param>
/// <param name="to">Recepient address</param>
/// <param name="bcc">Bcc recepient</param>
/// <param name="cc">Cc recepient</param>
/// <param name="subject">Subject of mail message</param>
/// <param name="body">Body of mail message</param>
public void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body) //, Label l, Panel p)
{
// Instantiate a new instance of MailMessage
MailMessage mMailMessage = new MailMessage();
// Set the sender address of the mail message
mMailMessage.From = new MailAddress(from);
// Set the recepient address of the mail message
mMailMessage.To.Add(new MailAddress(to));
// Check if the bcc value is null or an empty string
if ((bcc != null) && (bcc != string.Empty))
{
// Set the Bcc address of the mail message
mMailMessage.Bcc.Add(new MailAddress(bcc));
}
// Check if the cc value is null or an empty value
if ((cc != null) && (cc != string.Empty))
{
// Set the CC address of the mail message
mMailMessage.CC.Add(new MailAddress(cc));
} // Set the subject of the mail message
mMailMessage.Subject = subject;
// Set the body of the mail message
mMailMessage.Body = body;
// Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = true;
// Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal;
// Instantiate a new instance of SmtpClient
SmtpClient mSmtpClient = new SmtpClient(Mailserver);
// Send the mail message
try
{
mSmtpClient.Credentials = new System.Net.NetworkCredential(Username, Passwort);
mSmtpClient.Send(mMailMessage);
Label_Message.Text = "Danke für die Mitteilung!";
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
Label_Message.Text = errorMessage;
}
Panel_MailDialog.Visible = false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label_Message" runat="server"></asp:Label>
<asp:Panel ID="Panel_MailDialog" runat="server">
<table>
<tr>
<td valign="top" width="100">
<b>Deine E-Mail-Adresse</b>
</td>
<td valign="top">
<asp:TextBox ID="TextBox_Email" Width="300px" runat="server" Enabled="True"></asp:TextBox>
</td>
</tr>
<tr>
<td valign="top" width="100">
<b>Betrifft</b>
</td>
<td valign="top">
<asp:TextBox ID="TextBox_Subject" runat="server" Width="300px" Enabled="True"></asp:TextBox>
</td>
</tr>
<tr>
<td valign="top" width="100">
<b>Deine Nachricht</b>
</td>
<td valign="top">
<asp:TextBox ID="TextBox_Message" runat="server" Height="230px" TextMode="MultiLine"
Width="300px"></asp:TextBox>
</td>
</tr>
<tr>
<td valign="top" width="100">
<b></b>
</td>
<td valign="top">
<asp:Button ID="Button_Send" Width="300px" runat="server" OnClick="Button_Send_Click"
Text="Nachricht senden" />
</td>
</tr>
</table>
</asp:Panel>
</form>
</body>
</html>