📄 email2boss.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
namespace bgzdhxt
{
/// <summary>
/// email2boss 的摘要说明。
/// </summary>
public class email2boss : System.Web.UI.Page
{
public string strUserName="";
protected System.Web.UI.WebControls.TextBox 收件人_Textbox;
protected System.Web.UI.WebControls.TextBox 发件人_TextBox;
protected System.Web.UI.WebControls.TextBox 邮件主题_Textbox;
protected System.Web.UI.WebControls.Label Message;
protected System.Web.UI.WebControls.TextBox 邮件内容_TextBox;
protected System.Web.UI.WebControls.Button 发送_Button;
protected System.Web.UI.WebControls.Button 重填_Button;
protected System.Web.UI.WebControls.Button 返回_Button;
private string 发邮件者="";
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
try
{
发邮件者=Session["yonghuming"].ToString();
strUserName = "欢迎您, "+发邮件者;
发送_Button.Enabled=true;
收件人_Textbox.Text="hejiazidj@163.com";
}
catch
{
strUserName="您尚未登陆!";
发送_Button.Enabled=false;
Message.Text="您还没有登陆,不可以给总裁发送邮件,请先登陆!";
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.发送_Button.Click += new System.EventHandler(this.发送_Button_Click);
this.重填_Button.Click += new System.EventHandler(this.重填_Button_Click);
this.返回_Button.Click += new System.EventHandler(this.返回_Button_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void 发送_Button_Click(object sender, System.EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To = "hejiazidj@163.com";
//mail.To = "zhangyw1984@yahoo.com.cn";
mail.From ="nczhushuniugang@163.com";
mail.Subject = 发邮件者+"发送的 "+邮件主题_Textbox.Text;
mail.Body = 邮件内容_TextBox.Text.Replace(" "," ").Replace("\"",""").Replace("'","'").Replace("<","<").Replace(">",">").Replace("\r","<br>");
mail.Body+="<br><br><div align=right>发件人:"+发件人_TextBox.Text.Trim()+"</div>";
mail.BodyFormat = MailFormat.Html;//设置为HTML格式
//设置为需要用户验证
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置验证用户名
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "nczhushuniugang@163.com");
//设置验证密码
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","zhangywiwy*88");
try
{
SmtpMail.SmtpServer = "smtp.163.com";
SmtpMail.Send(mail);
Message.Text="发送成功!";
}
catch
{
Message.Text="邮件发送失败!可能是由于服务器忙,请重试!";
}
}
private void 重填_Button_Click(object sender, System.EventArgs e)
{
发件人_TextBox.Text="";
收件人_Textbox.Text="";
邮件主题_Textbox.Text="";
邮件内容_TextBox.Text="";
}
private void 返回_Button_Click(object sender, System.EventArgs e)
{
Response.Redirect("index.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -