/*
--===------------------------------------------===---
发送电子邮件
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);
}
}
}
}
发送电子邮件
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);
}
}
}
}