In the ASP, you can send a simple message by calling the CDONTS component, which is natural in the asp.net. The difference is that, in the. Net framework, this component is encapsulated into the System.Web.Mail namespace.
A typical mail-sending program is as follows:
<%@ Import namespace= "System.Web.Mail"%>
MailMessage mail=new MailMessage ();
Mail. From= "service@brookes.com";
Mail. To= "Brookes@brookes. COM ";
Mail. Bodyformat=mailformat.text;
Mail. body= "a test SMTP mail.";
Mail. Subject= "R u OK?";
smtpmail.smtpserver= "localhost";
Smtpmail.send (mail);
Typically, the system calls the default SMTP virtual server with IIS to deliver mail. However, you will often encounter such error prompts:
The server rejected one or more recipient addresses. The server response was:550 5.7.1 Unable to relay for brookes@brookes.com
There is an important reason for this error, in addition to the possibility of an incorrect address. As mentioned above, IIS does not carry true messaging functionality, but simply borrows an "SMTP virtual server" to enable forwarding of messages. In MSDN, you have the following tips:
If the local SMTP server (included in Windows 2000 and Windows Server 2003) is behind a firewall that blocks any direct SMTP traffic (via port 25), you will need to find out if there are any smart hosts available on the network that can be used to transfer to the Internet SMTP message.
A smart host is an SMTP server that can relay outgoing e-mail messages sent directly to the Internet from an internal SMTP server. A smart host should be able to connect to both the internal network and the Internet for use as an e-mail gateway.
Open the Default SMTP virtual Server-Properties-access-relay restrictions, and you can see that this forwarding or relaying function is limited. In the Limit list, add the IP addresses of the hosts that need to use this server to resolve the issues mentioned above.
If you do not use an SMTP virtual server with IIS and use other real mail servers, such as Imail,exchange, you often encounter problems with the server needing to send a sender authentication (ESMTP). An error occurs when you use a server that needs to verify the sender identity:
The server rejected one or more recipient addresses. The server response was:550 not local host ckocoo.com, not a gateway
Previously in ASP, there was no solution to this problem, and only the CDO component (CDONTS's parent component) could be used directly:
Conf. Fields[cdoconfiguration.cdosmtpauthenticate]. Value=cdoprotocolsauthentication.cdobasic;conf. Fields[cdoconfiguration.cdosendusername]. Value= "Brookes", Conf. Fields[cdoconfiguration.cdosendpassword]. Value= "XXXXXXX";
This requirement is clearly taken into account in the. Net Framework 1.1, which adds a fields set to the MailMessage component that increases the issue of sender authentication in the ESMTP mail server. However, this method applies only to the. NET Framework 1.1 and does not apply to the. NET Framework version 1.0. The mail-sending program with sender authentication is as follows:
<%@ Import namespace= "System.Web.Mail"%>
Ok? "; Mail. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); Basic Authentication mail. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendusername", "Brookes"); Set your username here mail. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendpassword", "Walkor"); Set your password here smtpmail.smtpserver= "Lsg.moon.net"; Smtpmail.send (mail);
With this method, you can finally no longer need to rely on JMail, easymail and other third-party components, and only simple use of Smtpmai can complete the delivery of the message!