//在项目里添加Interop.jmail.dll引用
private int SendEmail(string shoujianren, string biaoti, string bodys)
{
int count = 0;
jmail.Message eJmail = new jmail.Message();
string famail = "xmgl@126.com";
string pwds = "*********";
DateTime t = DateTime.Now;
String FromEmail = famail;//发件人邮箱
String ToEmail = shoujianren;//接受人邮箱
//Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false
eJmail.Silent = false;
//Jmail创建的日志,前提loging属性设置为true
eJmail.Logging = true;
//字符集,缺省为"US-ASCII"
eJmail.Charset = "gb2312";
//信件的contentype.缺省是"text/plain")字符串如果你以HTML格式发送邮件, 改为"text/html"即可。
//eJmail.ContentType = "text/html";
//添加收件人
eJmail.AddRecipient(ToEmail, "", "");
eJmail.From = FromEmail;
//发件人邮件用户名
eJmail.MailServerUserName = famail;//发件人邮箱
eJmail.FromName = "sfdfgfg";//发件人呢称
//发件人邮件密码
eJmail.MailServerPassWord = pwds;
//设置邮件标题
eJmail.Subject = biaoti;
//Jmail.AddAttachment("c:\\test.jpg", true, null);
//邮件内容
eJmail.HTMLBody = "<html><body><br>" + bodys;
eJmail.AppendHTML("<br><br></body></html>");
eJmail.Body = bodys;
eJmail.AppendHTML("");
//Jmail发送的方法
string smtps = "sffg.com";
if (eJmail.Send(smtps, false))
{
count++;
}
else
{
Response.Write("<script>alert('发送失败');history.back(-1);</script>");
}
eJmail.Close();
return count;
}
调用
SendEmail(mail.Text, "的风格合格后", bodys);