📄 mailme.aspx.cs
字号:
using System;
using System.Data;
using System.Text;
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 System.Web.Mail;
public partial class MailME : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox2.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
String servername = "";
String name = custString(TextBox2.Text.Trim());
string sReturn = string.Empty;
MailMessage mailMsg = new MailMessage();
mailMsg.BodyFormat = MailFormat.Html;
mailMsg.To = TextBox1.Text; //收件人
mailMsg.From = TextBox2.Text; //发件人
mailMsg.Subject = TextBox3.Text;//邮件的标题
mailMsg.Body = FreeTextBox1.Text;//邮件的主题
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", name);
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", TextBox4.Text.Trim());
SmtpMail.SmtpServer = DropDownList1.SelectedValue;
if (DropDownList1.SelectedValue == "smtp.126.com")
{
TextBox1.Text = "gdf87521@126.com";
}
else
{
TextBox1.Text = "gdf87521@163.com";
}
try
{
SmtpMail.Send(mailMsg);
// this.Label1.Text = "发送成功";
Response.Write("<script>alert('发送成功,等待管理员审批你的信息');</script>");
Response.Write("<script>window.close();</script>");
}
catch (Exception err)
{
Response.Write("<script>alert('发送失败');</script>");
}
}
public String custString(String id)
{
String T_id = id;
int len = T_id.Length;
String tmpString = "";
String okStr = "";
for (int i = 0; i <= len; i++)
{
tmpString = T_id.Substring(i, 1);
if (tmpString == "@")
{
return okStr;
}
else
{
okStr = okStr + tmpString;
}
}
return okStr;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue.Trim() == "smtp.126.com")
{
TextBox1.Text = "gdf87521@126.com";
}
else
{
TextBox1.Text = "gdf87521@163.com";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -