using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
sendMail("**@**.cn","深师家园", "admin@**.com", "admin@***.com", "***", "您好!", "这是一封测试邮件!");
} /// <summary>
/// 向用户发送邮件
/// </summary>
/// <param name="ReceiveUser">接收邮件的用户</param>
/// <param name="SendUser">发送者显求的邮箱地址,可为空</param>
/// <param name="DisplayName">收件人显示发件人的联系人名,可为中文</param>
/// <param name="SendUserName">发送者的邮箱登陆名,可以与发送者地址一样</param>
/// <param name="UserPassword">发送者的登陆密码</param>
/// <param name="MailTitle">发送标题</param>
/// <param name="MailContent">发送的内容</param>
public static void sendMail(string ReceiveUser, string DisplayName,string SendUser, string SendUserName, string UserPassword, string MailTitle, string MailContent)
{
MailAddress toMail = new MailAddress(ReceiveUser);//接收者邮箱
MailAddress fromMail = new MailAddress(SendUser, DisplayName);//发送者邮箱
MailMessage mail = new MailMessage(fromMail, toMail);
mail.Subject = MailTitle;
mail.IsBodyHtml = true;//是否支持HTML
mail.Body = MailContent;
SmtpClient client = new SmtpClient();
client.Host = "smtp.exmail.qq.com";//设置发送者邮箱对应的smtpserver
client.UseDefaultCredentials = false;
//client.Port = 465;
client.Credentials = new NetworkCredential(SendUserName, UserPassword);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
client.Send(mail);
}
catch(SmtpException ex)
{
Console.Write(ex.Message);
}
Console.ReadKey();
}
}
}