许明会的计算机技术主页

Language:C,C++,.NET Framework(C#)
Thinking:Design Pattern,Algorithm,WPF,Windows Internals
Database:SQLServer,Oracle,MySQL,PostSQL
IT:MCITP,Exchange,Lync,Virtualization,CCNP

导航

TCP编程(4): 发送电子邮件 MailMessage, SmtpClient, NetworkCredential

/*--===------------------------------------------===---
发送电子邮件
SmtpClient, MailMessage, NetworkCredential

            许明会    21:59:45 2007年12月9日
--===------------------------------------------===---
*/
using System;
using System.Collections.Generic;
using System.Text;

using System.Net.Mail;

namespace NetCommunication
{
    
class SendMail
    {
        
static void Main()
        {
            
try
            {
                
//准备邮件内容
                MailMessage mail = new MailMessage("flaaash@163.com""flaaash@126.com""邮件主题""邮件内容");
                mail.Attachments.Add(
new Attachment(@"C:\IO.SYS"));
                mail.Priority 
= MailPriority.High;
                mail.IsBodyHtml 
= false;
                
//准备安全凭证
                System.Net.NetworkCredential nc = new System.Net.NetworkCredential("flaaash""password");
                
//准备SMTP,发送电子邮件
                SmtpClient sc = new SmtpClient("smtp.163.com"25);
                sc.DeliveryMethod
= SmtpDeliveryMethod.Network;
                sc.Credentials 
= nc;
                sc.Send(mail);
                Console.WriteLine(
"邮件发送成功!");
            }
            
catch (SmtpException se)
            {
                Console.WriteLine(se.Message);
            }
        }
    }
}

posted on 2007-12-09 23:55  许明会  阅读(910)  评论(0编辑  收藏  举报