www.chinacs.net2002-5-9中文c#技術站
郵件傳送類,支援html格式,支援優先順序設定。通過socket類實現的
using system;
using system.text;
using system.io;
using system.net;
using system.net.sockets;
namespace blood.com.classlib
public void sendcommandtoserver(string command)
public string getserverresponse()
else }
public bool doesstringcontainsmtpcode(string s,string smtpcode)
} //結束類
///
/// 傳送郵件類
///
public class smtpmail
///
/// 取得錯誤反饋資訊
///
public string errormessage
}///
/// 取得smtp伺服器反饋的資訊
///
public string serverresponse
}///
/// 郵件傳送優先順序
///
public enum prioritys
public void sendmail(string smtphost,int port,string from,string displayfromname,string to,string displaytoname,prioritys priority,bool html,string base,string subject,string message)
//讀取反饋資訊
strresponsenumber = smtpcmail.getserverresponse();
if (smtpcmail.doesstringcontainsmtpcode(strresponsenumber,"220"))
else
string strsendbuffer = new string[6];
string strresponsecode = ; // success codes from smtp server
string strdata = "";
strdata = string.concat("helo ",smtphost);
strdata = string.concat(strdata,"\r\n");
strsendbuffer[0] = strdata ;
strdata = "";
strdata = string.concat("mail from: ","<" + from + ">");
strdata = string.concat(strdata,"\r\n");
strsendbuffer[1] = strdata;
strdata = "";
strdata = string.concat("rcpt to: ","<" + to + ">");
strdata = string.concat(strdata,"\r\n");
strsendbuffer[2] = strdata;
strdata = "" ;
strdata = string.concat("data","\r\n");
strsendbuffer[3] = strdata ;
strdata = "" ;
strdata = string.concat("from: ",displayfromname + "<" + from + ">");
strdata = string.concat(strdata,"\r\n" );
strdata = string.concat(strdata,"to: " );
strdata = string.concat(strdata,displaytoname + "<" + to + ">");
strdata = string.concat(strdata,"\r\n" );
strdata = string.concat(strdata,"subject: " );
strdata = string.concat(strdata,subject);
strdata = string.concat(strdata,"\r\n");
strdata = string.concat(strdata,"mime-version: 1.0" );
strdata = string.concat(strdata,"\r\n");
strdata = string.concat(strdata,"x-priority: " + priority);
strdata = string.concat(strdata,"\r\n");
strdata = string.concat(strdata,"x-msmail-priority: " + priority);
strdata = string.concat(strdata,"\r\n");
if(html == true)
else
strdata = string.concat(strdata,"\r\n");
strdata = string.concat(strdata,"charset=\"iso-8859-1\"" );
strdata = string.concat(strdata,"\r\n");
if(html == true)
else
strdata = string.concat(strdata,"\r\n");
strdata = string.concat(strdata,"content-base: \"" + base + "\"" );
strdata = string.concat(strdata,"\r\n" + "\r\n");
strdata = string.concat(strdata,message);
strdata = string.concat(strdata,"\r\n.\r\n");
strsendbuffer[4] = strdata;
strdata = "" ;
strdata = string.concat(strdata,"quit\r\n");
strsendbuffer[5] = strdata;
int i = 0 ;
while(i < strsendbuffer.length)
// 結束迴圈
}catch(socketexception err)
catch(exception e)
} //結束郵件傳送方法
} // 結束類
} // 結束namespace
郵件傳送前台頁面
<%@ page language="c#" codebehind="webform1.aspx.cs" autoeventwireup="false" inherits="test.sendmailsample" %>
郵件傳送codebehind
using system;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using blood.com.classlib;
namespace test
#region web form designer generated code
override protected void oninit(eventargs e)
///
/// required method for designer support - do not modify
/// the contents of this method with the code editor.
///
private void initializecomponent()
#endregion
private void btnsendmail_click(object sender, system.eventargs e)
else if(ddlpriority.selecteditem.text == "高")
else if(ddlpriority.selecteditem.text == "低")
if(ddlhtml.selecteditem.text == "是")
else
clsmail.sendmail(strsmtphost,intport,strfrom,strfromname,strto,strtoname,priority,bolhtml,"",strsubject,strmessage);
if(clsmail.errormessage !="")
else}}
}}
郵件傳送類,支援HTML格式,支援優先順序設定
郵件傳送類,支援html格式,支援優先順序設定。通過socket類實現的 using system using system.text using system.io using system.net using system.net.sockets namespace blood.com.clas...
郵件傳送類,支援HTML格式,支援優先順序設定
chinacs.2002 5 9 中文c 技術站 郵件傳送類,支援html格式,支援優先順序設定。通過socket類實現的 using system using system.text using system.io using system.using system.sockets namespa...
傳送郵件,支援群發,非常好用
傳送郵件 public class smtpmanager else mail.to.add newmailaddress address,displayname 設定郵件的抄送收件人 這個就簡單多了,如果不想快點下崗重要檔案還是cc乙份給領導比較好 mailaddress manage hotma...