sendingmail.aspx
来自「东软内部材料(四)asp等相关的教学案例 」· ASPX 代码 · 共 61 行
ASPX
61 行
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Mail" %>
<html>
<head>
<!--------------------------------------------------------------------------->
<script language="c#" runat="server">
void Page_Load(Object Sender, EventArgs E)
{
SqlConnection myConnection;
string ConnStr;
int i;
int x = 0;
int y = 0;
// set the connection details
ConnStr = "Server=localhost; database=_pubs; UID=sa";
try
{
myConnection = new SqlConnection(ConnStr);
myConnection.Open();
i = x / y;
}
catch (SqlException exSQL)
{
SendMail(exSQL.ToString());
}
catch (Exception ex)
{
SendMail(ex.ToString());
}
finally
{
}
}
void SendMail(string message)
{
MailMessage MyMessage = new MailMessage();
MyMessage.To = "webmaster@yourcompany.com";
MyMessage.From = "ASPApplication@yourcompany.com";
MyMessage.Subject = "Unhandled ASP.NET Error";
MyMessage.BodyFormat = MailFormat.Text;
MyMessage.Body = message;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(MyMessage);
}
</script>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?