这是msdn中的一个例子,但我用vs.net 2003编译时说找不到 System.Web.Mail,请问这是为什么呀?我在系统是XP.我是新建的一个windows applicaton,然后把代码复制到form1.cs 中编译的.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 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());
}
}
}
}
解决方案 »
- 请问,多次Fill,会怎么样?
- .net 2003 service 发邮件在本机没问题,但是放到服务器上就发不出去
- 关于窗口控件显示最大化的一个问题
- SQL中能用,C#中不能用的SQL~~~
- 判断鼠标焦点位置
- ************************初学者的问题,请帮忙我!*******************************
- 求助!在C#中如何停止一个已经触发的时间?谢谢!
- 请教各位大哥。。。多谢!!
- 我在安装PDFFactory2.24的时候,提示我安装.net framework SDK
- 大家好,急切请教一个问题!!
- 请教一个输出问题,输出常量也不能成功
- 多线程中的事件问题
如果没有System.Web.dll,那么你就要重装.net framework了。
上面那段代码是发不出邮件的。你搜索一下CSDN发邮件的旧贴。
http://www.systemwebmail.com/default.aspx
// 使用SmtpMail对象发送邮件MailMessage mailObj = new MailMessage(); mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置需要验证
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username); //用户名
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); //密码我觉得username,password 不会是你登录邮箱时的username&password吧?因为后面还有:
// 设置邮件的发送及接收地址
mailObj.From = from;
mailObj.To = sendto;
而且发邮件也用不着username&password 吧?