今天朋友需要做个自动发送邮件的功能,我就查了一下资料
做了个简单Demo,现在贴出来:
using System.Text;
using System.Net;
using System.Net.Mail;
public class MnaipulateEmail
{
public static void Send(string MessageFrom, string MessageTo, string MessageSubject, string MessageBody)
{
try
{
MailMessage message = new MailMessage();
message.From = new MailAddress(MessageFrom); //发送邮箱地址,测试用的是 xx@163.com
message.To.Add(new MailAddress(MessageTo)); //收件人地址,任意
message.Subject = MessageSubject; //标题
message.SubjectEncoding = Encoding.UTF8; //转码,当然,这个依据情况来
message.Body = MessageBody; //正文
SmtpClient client = new SmtpClient("STMP服务名,如stmp.163.com"); //创建Smtp实例
client.Credentials = new NetworkCredential("邮箱用户", "邮箱密码"); // 添加验证信息
client.Send(message); //发送邮件
}
catch (Exception ex)
{
throw ex;
}
}
}
总而言之,使用Microsoft封装好的Mail空间下的类来实现这个需求还是很简单的.