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

类别:.NET开发 点击:0 评论:0 推荐:

这两天做了一个小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回去。

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

本文地址:http://com.8s8s.com/it/it42559.htm