在.Net Framework 1.1中,对这一需求有了考虑,在MailMessage组件中增加了Fields集合易增加ESMTP邮件服务器中的寄送者身份验证的问题。不过,这一方法仅适用于.Net Framework 1.1,不适用于.Net Framework 1.0版本。带有寄送者身份验证的邮件发送程序如下:
<%@ Import Namespace="System.Web.Mail" %> <script runat="server"> 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="hello." 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); </script>
不过这种方法对sina的邮件不管用,希望大家注意
|