去看看System.Web.Mail 包的SmtpMail 这是MSDN的例子 using System; using System.Web.Mail;
namespace SendMail { class usage { public void DisplayUsage() { Console.WriteLine("Usage SendMail.exe <to> <from> <subject> <body>"); Console.WriteLine("<to> the addresses of the email recipients"); Console.WriteLine("<from> your email address"); Console.WriteLine("<subject> subject of your email"); Console.WriteLine("<body> the text of the email"); Console.WriteLine("Example:"); Console.WriteLine("SendMail.exe [email protected];[email protected][email protected] Hi hello"); } } class Start { // The main entry point for the application. [STAThread] static void Main(string[] args) { try { try { MailMessage Message = new MailMessage(); Message.To = args[0]; Message.From = args[1]; Message.Subject = args[2]; Message.Body = args[3]; try { SmtpMail.SmtpServer = "your mail server name goes here"; SmtpMail.Send(Message); } catch(System.Web.HttpException ehttp) { Console.WriteLine("{0}", ehttp.Message); Console.WriteLine("Here is the full error message output"); Console.Write("{0}", ehttp.ToString()); } } catch(IndexOutOfRangeException) { usage use = new usage(); use.DisplayUsage(); } } catch(System.Exception e) { Console.WriteLine("Unknown Exception occurred {0}", e.Message); Console.WriteLine("Here is the Full Message output"); Console.WriteLine("{0}", e.ToString()); } } } }
http://blog.joycode.com/ghj/archive/2005/10/01/64458.aspxhttp://www.aspxboy.com/490/default.aspx
这是MSDN的例子 using System;
using System.Web.Mail;
namespace SendMail
{
class usage
{
public void DisplayUsage()
{
Console.WriteLine("Usage SendMail.exe <to> <from> <subject> <body>");
Console.WriteLine("<to> the addresses of the email recipients");
Console.WriteLine("<from> your email address");
Console.WriteLine("<subject> subject of your email");
Console.WriteLine("<body> the text of the email");
Console.WriteLine("Example:");
Console.WriteLine("SendMail.exe [email protected];[email protected] [email protected] Hi hello");
}
}
class Start
{
// The main entry point for the application.
[STAThread]
static void Main(string[] args)
{
try
{
try
{
MailMessage Message = new MailMessage();
Message.To = args[0];
Message.From = args[1];
Message.Subject = args[2];
Message.Body = args[3]; try
{
SmtpMail.SmtpServer = "your mail server name goes here";
SmtpMail.Send(Message);
}
catch(System.Web.HttpException ehttp)
{
Console.WriteLine("{0}", ehttp.Message);
Console.WriteLine("Here is the full error message output");
Console.Write("{0}", ehttp.ToString());
}
}
catch(IndexOutOfRangeException)
{
usage use = new usage();
use.DisplayUsage();
}
}
catch(System.Exception e)
{
Console.WriteLine("Unknown Exception occurred {0}", e.Message);
Console.WriteLine("Here is the Full Message output");
Console.WriteLine("{0}", e.ToString());
}
}
}
}
using System.Web.Mail;namespace LiveMessage.Common
{
/// <summary>
/// SendMail 的摘要说明。
/// </summary>
public class SendMail
{
public SendMail()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public static bool sendMail(string from,string to,string subject,string body,string smtpaccountname,string sendusername,string sendpassword,string smtpServer)
{
try
{
MailMessage mm=new MailMessage();
mm.BodyFormat=MailFormat.Html;
mm.From=from;
mm.To=to;
mm.BodyEncoding=System.Text.Encoding.GetEncoding(936);
mm.Subject=subject;
mm.Body=body;
mm.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
mm.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"] = smtpaccountname;
mm.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sendusername;//验证账号:发送者邮箱账号
mm.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = sendpassword; //验证密码:发送者邮箱密码
mm.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; //验证级别0,1,2
mm.Fields["http://schemas.microsoft.com/cdo/configuration/languagecode"] = 0x0804;//语言代码
System.Web.Mail.SmtpMail.SmtpServer=smtpServer;//上句和这句重着,这句可以替代上句
System.Web.Mail.SmtpMail.Send(mm);
return true;
}
catch
{
return false;
}
}
}
}