首先安装jmail free 4.5 然后在.net项目里,添加引用->COM 找到JMail 4.0 Library(按字母J可以快速找到)
加入引用以后,增加Jmail类,代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using jmail;
namespace BLL
{
public class Jmail
{
public static bool SendMail(string from, string to, string subject, string body)
{
jmail.Message m = new Message();
m.Charset = "gb2312";
m.From = from;
m.Subject = subject;
m.AddRecipient(to, null, null);
m.MailServerUserName = "www.svnhost.cn@163.com";
#region password
m.MailServerPassWord = "www.svnhost.cn";
#endregion
m.ContentType = "text/html";
m.Body = body;
m.Send("smtp.163.com", false);
return true;
}
}
}
然后就可以发送Email了,如果开发机或者服务器安装了杀毒软件可能会拦截邮件发送,需要关闭杀毒软件的“邮件蠕虫........”这个选项,还有邮件服务器,需要支持SMTP功能。