有用到需要发送帐号激活邮件,利用Jmail去做很简单的,先记录下:
1.首先到Jmail官网下载对应的版本,解压后安装(Jmail 4.4 免费版)。
2.到安装目录就可以找到jmail.dll文件,引用就可以了
3.下面是个很简单的发送邮件的方法,网上也有有很多实例的。
- /// <summary>Jmail发送邮件 </summary>
- /// <param name="Tomail">接收邮件的邮箱地址</param>
- /// <param name="subject">主题</param>
- /// <param name="body">内容</param>
- /// <returns></returns>
- public static bool SendMail(string Tomail, string subject, string body)
- {
- string smtpServer = ConfigurationManager.AppSettings["smtpServer"].ToString().Trim();//发送邮箱的STMP服务器
- string fromMail = ConfigurationManager.AppSettings["smtpMail"].ToString().Trim();//发送邮件的邮箱帐号
- string fromMailPass = ConfigurationManager.AppSettings["amtpPwd"].ToString().Trim();//发送邮件的邮箱密码
- try
- {
- jmail.Message jmail = new jmail.Message();
- jmail.From = fromMail;
- jmail.AddRecipient(Tomail, null, null);
- jmail.MailServerUserName = fromMail;
- jmail.MailServerPassWord = fromMailPass;
- jmail.Subject = subject;
- jmail.Body = body;
- jmail.Charset = "GB2312";
- jmail.ContentType = "text/html";
- jmail.Send(smtpServer, false);
- jmail.Close();
- return true;
- }
- catch
- {
- return false;
- }
- }
复制代码
|
|