002_.Net Email

SourceCode1:

      //--需追加引用类 using System.Net.Mail;

       SmtpClient client = new SmtpClient();
        client.Host = "your_smtp";
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential("email_userid","emai_password");
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        MailMessage message = new MailMessage("
sender_email","receiver_email");
        message.Subject = "asp.net Email Test";
        message.Body = "用自己写的软件发的邮件";
        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.IsBodyHtml = true;
        Attachment data = new Attachment("C:\\student.xml");
        message.Attachments.Add(data);
        try
        {
            client.Send(message);
            Response.Write("Success!");
        }
        catch(Exception err)
        {
            Response.Write("fail");
        }

//*******************

SourceCode2:

  //--需追加引用类 using System.Web.Mail;

//把错误信息发送到作者
   string strPageUrl = Request.Path;
   Exception ErrorInfo =Server.GetLastError();
   //Server.ClearError();
   string strMessage = "Url:" + strPageUrl + "</br>";
   strMessage = strMessage + " Error: ";
   strMessage = strMessage + ErrorInfo.ToString() + "</br>";

            MailMessage Mymessage = new MailMessage();
   Mymessage.To = "shaoxufeng@fujitec.com.cn";
            Mymessage.From = "shaoxufeng@fujitec.com.cn";
            Mymessage.Subject = "ASP.NET Error";
            Mymessage.BodyFormat = MailFormat.Text;
            Mymessage.Body = strMessage;

            Mymessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");  //basic authentication
            Mymessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "shaoxufeng");//set your username here
            Mymessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "shaoxufeng3600"); //set your password here
           // SmtpMail.SmtpServer="lsg.moon.net";
            SmtpMail.SmtpServer = "mail.fujitec.com.cn";
            SmtpMail.Send(Mymessage);


 

posted on 2009-03-04 08:45  shao  阅读(166)  评论(0编辑  收藏  举报

导航