利用SmtpMail发送邮件,怎么通过SMTP服务器认证?

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

using System;
using System.Web.Mail;

namespace testSendmail
{
   class testsend
    {
        MailMessage myem=new MailMessage();
        myem.To    =    "[email protected]";     //    收件人
        myem.From    =  "[email protected]";    //    发件人
        myem.Subject    =    "怎么通过SMTP服务器认证";    //主旨
        myem.Body = "利用SmtpMail发送邮件,怎么通过SMTP服务器认证?"; //内容
        myem.Priority=MailPriority.High; //优先级
        
        //最关键的来了:-)
        myem.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");     //这个好像是认证类型
        myem.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");     //要认证的用户名
        myem.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");    //要认证的密码 

         static void Main()
         {
              try
               {
                    SmtpMail.SmtpServer="smtp.163.com";     //    SMTP服务器
                    SmtpMail.Send(myem);
               }
               catch(System.Web.HttpException e)
               {
                    Console.WriteLine(“异常信息: "+e.Message+"\n异常源: "+e.Source);
               }      
         }
       }
}

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