关于smtp的问题,真的可以解决哦!我就是这样成功的!

这两天做了一个小 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 ,选择属性,在 ACCESS 中点 RELAY ,增加 127.0.0.1 。一路 OK 回去。

这时候再运行程序,邮件发送成功。

Published At
Categories with Web编程
Tagged with
comments powered by Disqus