[Mono-devel-list] Mail example and path problems for attachments.

Jason Starin | Giant Head jasonstarin at giant-head.com
Mon Jan 17 17:18:25 EST 2005


This example: http://www.eggheadcafe.com/articles/20011002.asp
Needs what to operate properly in the mono default test directory?


<%@ Page Language="C#" debug="true" %>
<%@ Import NameSpace="System.Web.Mail" %>
<script runat="server">
protected void Page_Load(Object Sender, EventArgs e) {
if(!Page.IsPostBack)
Info.Text = "Sending E-Mail using C# ";
}
protected void Send_Email(Object Sender, EventArgs e) {
string sPath = "";
string fileTitle ="";
MailMessage mail = new MailMessage();
mail.To = Request.Form["to"];
mail.From = Request.Form["from"];
if(Request.Form["format"].Equals("text"))
mail.BodyFormat = MailFormat.Text;
else
mail.BodyFormat = MailFormat.Html;

mail.Subject = Request.Form["subject"];
mail.Body = Request.Form["body"];
SmtpMail.SmtpServer = Request.Form["server"];
if(Request.Form["attachment"]!="") 
sPath="\\secure\\attachments\\temp\\";
fileTitle = attachment.PostedFile.FileName;
fileTitle = fileTitle.Substring(fileTitle.LastIndexOf("\\") + 1);
attachment.PostedFile.SaveAs(sPath+ fileTitle);
mail.Attachments.Add(new MailAttachment(sPath+fileTitle));
System.IO.File.Delete(sPath+ fileTitle);
try{ SmtpMail.Send(mail); } 
catch(Exception MailEx){Info.Text+=MailEx.Message;}
finally{
Info.Text = "Info Sent...<br><br>" + "<a href=\"sendMail.aspx\">Send
Another?</a>";
}
}
</script>
<html>
<head>
<title>Sending E-Mail using C#</title>
<style>
a { font-size:11pt; font-family:Verdana; font-weight:normal; color:salmon; }
</style>

</head>
<body bgcolor="white">
<basefont face=Verdana>
<p align="center" >
<asp:label id="Info" runat="server" />
</p> 
<% if(!Page.IsPostBack) { %>
<p align="center">All fields required.</p>
<form method="post" runat="server" enctype="multipart/form-data" > 
<table width="60%" border="0" align="center" cellpadding="2" cellspacing="2"
bgcolor="#FFCC66">
<tr ><td width="20%" align="right">MailServer :</td>
<td><input type="text" name="server" id="server" runat="server">
<asp:RequiredFieldValidator id="serverRequired" runat="server"
ControlToValidate="server"
ErrorInfo="<small>Email server required.</small>"
Display="Dynamic">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr >
<td width="20%" align="right">From :</td>
<td><input type="text" name="from" id="from" runat="server">
<asp:RegularExpressionValidator id="fromEmail" runat="server"
ControlToValidate="from"
ValidationExpression=".*@.*\..*"
ErrorInfo="<small>Invalid email address.</small>"
Display="Dynamic">
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator id="fromRequired" runat="server"
ControlToValidate="from"
ErrorInfo="<small>From Email required.</small>"
Display="Dynamic">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">To : </td>
<td><input type="text" name="to" id="to" runat="server">
<asp:RegularExpressionValidator id="toEmail" runat="server"
ControlToValidate="to"
ValidationExpression=".*@.*\..*"
ErrorInfo="<small>Invalid email address.</small>"
Display="Dynamic">
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator id="toRequired" runat="server"
ControlToValidate="to"
ErrorInfo="<small>To email address required.</small>"
Display="Dynamic">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">Mail Format : </td>
<td>
<select name="format">
<option value="text">Text</option>
<option value="html">HTML</option>
</select>
</td>
</tr>
<tr>
<td align="right">Subject : </td>
<td><input type="text" name="subject" id="subject" style="width:400;"
runat="server">
<asp:RequiredFieldValidator id="subjectRequired" runat="server"
ControlToValidate="subject"
ErrorInfo="<small>Email subject required.</small>"
Display="Dynamic">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td valign="top" colspan="2" align="center">Body : </td>
</tr>
<tr>
<td colspan="2" align="center"><textarea cols="5" rows="10" name="body"
id="body" style="width:400;" runat="server">
</textarea>
<asp:RequiredFieldValidator id="bodyRequired" runat="server"
ControlToValidate="body"
ErrorInfo="<BR><small>Email Info required.</small>"
Display="Dynamic">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td valign="top" align="right">Attachment : </td>
<td><input type="File" id="attachment" name="attachment"
runat="server"></td>
</tr>
<tr>
<td colspan=2 align="center">
<input type="submit" OnServerClick="Send_Email" runat="server" value="Send
Mail " />
</td>
</tr>
</table>
</form>
<% } %>
</body>
</html>
 


 Jason





More information about the Mono-devel-list mailing list