用 ASP.Net 发Email

来源:互联网 发布:mac怎么打特殊符号 编辑:程序博客网 时间:2024/05/16 05:03

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 PWDGet
{
 /// <summary>
 /// Summary description for passwordGet.
 /// </summary>
 public class passwordGet : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Panel PanelError;
  protected System.Web.UI.WebControls.Panel panelMessage;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   if(!this.IsPostBack)   
   {    
    try
    {//send Email code
     MailMessage Mail=new MailMessage();

     Mail.From =strFromMan;
     Mail.To = strToMan;

     Mail.Subject =" ASC Wines Password Assistance";

     Mail.Body ="<html><head> <body>message</body></html>";
     Mail.BodyFormat=MailFormat.Html;
     
     Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
     Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","test");//这里填写你邮箱的用户名
     Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","ssbgroup");//你邮箱的密码

     SmtpMail.SmtpServer= "mail.ssbg.com.cn";  // 邮件服务器
 SmtpMail.Send(Mail);  

     //Response.Write("succeed!...");
    }
    catch
    {
     this.PanelError.Visible = true;
     this.panelMessage.Visible = false;
     
    }
   }
  }

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {   
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion
 }
}

原创粉丝点击