MailME.aspx.cs
上传用户:shjujing
上传日期:2022-07-28
资源大小:11244k
文件大小:3k
源码类别:

Email客户端

开发平台:

Visual C++

  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Configuration;
  5. using System.Collections;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. using System.Web.Mail;
  13. public partial class MailME : PageBase
  14. {
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.         TextBox2.Focus();
  18.     }
  19.     protected void Button1_Click(object sender, EventArgs e)
  20.     {
  21.         String servername = "";
  22.         String name = custString(TextBox2.Text.Trim());
  23.         string sReturn = string.Empty;
  24.         MailMessage mailMsg = new MailMessage();
  25.         mailMsg.BodyFormat = MailFormat.Html;
  26.         mailMsg.To = TextBox1.Text; //收件人
  27.         mailMsg.From = TextBox2.Text; //发件人
  28.         mailMsg.Subject = TextBox3.Text;//邮件的标题 
  29.         mailMsg.Body = content.Text;//邮件的正文
  30.         mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
  31.         mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", name);
  32.         mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", TextBox4.Text.Trim());
  33.         SmtpMail.SmtpServer = DropDownList1.SelectedValue;
  34.         if (DropDownList1.SelectedValue == "smtp.126.com")
  35.         {
  36.             TextBox1.Text = "gdf87521@126.com";
  37.         }
  38.         else
  39.         {
  40.             TextBox1.Text = "gdf87521@163.com";
  41.         }
  42.         try
  43.         {
  44.             SmtpMail.Send(mailMsg);
  45.             // this.Label1.Text = "发送成功";
  46.             Response.Write("<script>alert('发送成功,等待管理员审批你的信息');</script>");
  47.             Response.Write("<script>window.close();</script>");
  48.         }
  49.         catch (Exception err)
  50.         {
  51.             Response.Write("<script>alert('发送失败');</script>");
  52.         }
  53.     }
  54.     public String custString(String id)
  55.     {
  56.         String T_id = id;
  57.         int len = T_id.Length;
  58.         String tmpString = "";
  59.         String okStr = "";
  60.         for (int i = 0; i <= len; i++)
  61.         {
  62.             tmpString = T_id.Substring(i, 1);
  63.             if (tmpString == "@")
  64.             {
  65.                 return okStr;
  66.             }
  67.             else
  68.             {
  69.                 okStr = okStr + tmpString;
  70.             }
  71.         }
  72.         return okStr;
  73.     }
  74.     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  75.     {
  76.         if (DropDownList1.SelectedValue.Trim() == "smtp.126.com")
  77.         {
  78.             TextBox1.Text = "gdf87521@126.com";
  79.         }
  80.         else
  81.         {
  82.             TextBox1.Text = "gdf87521@163.com";
  83.         }
  84.     }
  85. }