MailME.aspx.cs
资源名称:yjal.rar [点击查看]
上传用户:shjujing
上传日期:2022-07-28
资源大小:11244k
文件大小:3k
源码类别:
Email客户端
开发平台:
Visual C++
- 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 = content.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";
- }
- }
- }