.Net2.0最简单的邮件发送程序
注意现在的邮件服务器一般都要求验证。求证了一阵才知道怎么设置验证信息。一般都很简单啦,下面是最简单的代码:
namespace mailTest
{
class Program
{
static void Main(string[] args)
{
string strFromAddr = //put the from address
MailAddress from = new MailAddress(strFromAddr);
MailAddress to = new MailAddress("xiaoyi__xy@163.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an e-mail message from an application very easily.";
string server = "smtp.163.com";
SmtpClient client = new SmtpClient(server);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(strUserName, strUserPassword);//Note here, credential validation is required.
Console.WriteLine("Sending an e-mail message to {0} by using SMTP host {1} port {2}.",
to.ToString(), client.Host, client.Port);
client.Send(message);
Console.ReadKey();
}
}
}
namespace mailTest
{
class Program
{
static void Main(string[] args)
{
string strFromAddr = //put the from address
MailAddress from = new MailAddress(strFromAddr);
MailAddress to = new MailAddress("xiaoyi__xy@163.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an e-mail message from an application very easily.";
string server = "smtp.163.com";
SmtpClient client = new SmtpClient(server);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(strUserName, strUserPassword);//Note here, credential validation is required.
Console.WriteLine("Sending an e-mail message to {0} by using SMTP host {1} port {2}.",
to.ToString(), client.Host, client.Port);
client.Send(message);
Console.ReadKey();
}
}
}