這兩天做了一個小PROJECT,大致是一個SERVER監控系統,如果發現某部SERVER有異常,發送EMAIL到相關手機,以便在非工作時間和節假日也能及時知道系統故障。
其中一個功能就是發送EMAIL。程序是這樣的:
myMailMsg.To = "
[email protected]";
myMailMsg.From = "
[email protected]";
myMailMsg.Subject = "server down";
myMailMsg.Body = "Please call StarLan to chen Database Server";
myMailMsg.BodyFormat = MailFormat.Text;
SmtpMail.SmtpServer="localhost";
SmtpMail.Send(myMailMsg);
本來是用外部的SMTP SERVER
SmtpMail.SmtpServer="smtp.XXX.com";
但後來發現由於DATA CENTER的FIREWALL原因,改用
SmtpMail.SmtpServer="localhost";
運行後系統提示錯誤信息:
Email Fail
Could not Access ''CDO.Message'' object.
Here is the full error message output:
System.Web.HttpException: Could not Access ''CDO.Message'' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x8004020F): The server rejected one or more recipIEnt addresses. The server response was: 550 5.7.1 Unable to relay for
[email protected] 檢查SMTP SERVICE,正常,估計是權限設置問題。打開IIS ADMIN,右鍵點擊SMTP VIRTUAL SERVER(默認SMTP虛擬服務器),選擇屬性,在Access(訪問)中點RELAY(中繼),增加127.0.0.1。一路OK回去。
這時候再運行程序,郵件發送成功。