sendmessage.aspx.cs

来自「《征服Ajax》原书的例题源码」· CS 代码 · 共 56 行

CS
56
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mail;

public partial class server_SendMessage : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		bool send = false;
		if ((Request.Params["hid_username"] != null) &&
			(Request.Params["hid_password"] != null) &&
			(Request.Params["hid_from"] != null) &&
			(Request.Params["hid_to"] != null) &&
			(Request.Params["hid_subject"] != null) &&
			(Request.Params["hid_body"] != null))
		{
			// 用户名
			string username = Request.Params["hid_username"];

			// 密码
			string password = Request.Params["hid_password"];

			// 发件人
			string from = Request.Params["hid_from"];

			// 收件人
			string to = Request.Params["hid_to"];

			// 邮件主题
			string subject = Request.Params["hid_subject"];

			// 邮件内容
			string body = Request.Params["hid_body"];

			// 创建LocalMailService类对象,用于访问本机的邮件服务
			ServerSetting smtp = new ServerSetting("localhost", 25, username, password);
			ServerSetting pop3 = new ServerSetting("localhost", 110, username, password);
			MailService mailService = new LocalMailService(smtp, pop3);

			// 发送邮件
			send = mailService.SendMail(from, to, subject, body);
		}

		// 输出错误提示信息或者直接关闭窗口
		Response.Write(send ? "<script>window.close();</script>" : "<script>alert('邮件发送失败');</script>");
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?