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());
}
}
}
}
2.右击SMTP服务中的"域",在弹出的菜单中选择"新建"-"域"
3.在"新建SMTP域向导"中选择"远程"
4.在"名称"中输入你要外发的邮件的域名,一般情况下[email protected]的邮件域名就输入"*.com",如果是[email protected]就输入"*.net",以此类推.
5.在新加入的域上右击,选择"属性"
6.在"属性"窗口中选择"允许将传入邮件中继到此域","发送HELO,而不是EHLO","使用DNS以发送到此域"
7.确定
此时,就完成了SMTP 外发邮件到.com域的配置工作.其它域以此类推即可.此时,用自己的代码实现发送邮件或用Foxmail,OE等邮件客户端都可以实现用该主机外发邮件的功能.
我按上面说的配的
mMail.Subject="Subject";
mMail.From="[email protected]";
mMail.To="[email protected]";
mMail.Body="Mail body.";System.Web.Mail.SmtpMail.SmtpServer="localhost";
System.Web.Mail.SmtpMail.Send(mMail);就用以上的代码就可以实现邮件发送,SmtpServer设置成已经配置了SMTP Service的主机名或是IP即可.