/// <summary> /// 发送邮件 /// </summary> /// <param name="tomail">收件人邮件地址</param> /// <param name="title">标题</param> /// <param name="content">邮件正文</param> /// <param name="FromUser">发件人账号</param> /// <param name="userPwd">注意:如果发件人密码测试不通过的话,就用授权码。授权码的设置:登陆发送方→设置→协议那设置</param> public static void sendEmail(string tomail, string title, string content, string FromUser, string userPwd) { MailAddress from = new MailAddress(FromUser); MailAddress to = new MailAddress(tomail); MailMessage MyMessage = new MailMessage(from, to); MyMessage.Priority = MailPriority.Normal; MyMessage.Priority = MailPriority.Normal; MyMessage.IsBodyHtml = false; MyMessage.IsBodyHtml = true; MyMessage.Body = content; MyMessage.BodyEncoding = System.Text.Encoding.UTF8; MyMessage.Subject = title; string SmtpServer = "smtp.163.com";//这里使用你服务器端发送的邮箱smtp协议 # #新浪邮箱的:<strong></strong><pre name="code" class="csharp" style="display: inline !important; "><pre name="code" class="csharp" style="display: inline !important; ">smtp.sina.com网易邮箱:"smtp.126.com"; QQ邮箱:smtp.qq.com</pre><pre name="code" class="csharp" style="display: inline !important; "> SmtpClient client = new SmtpClient(SmtpServer); System.Net.NetworkCredential cred = new System.Net.NetworkCredential(FromUser, userPwd); client.Credentials = cred; client.Send(MyMessage); }
string email = "1354370987@qq.com"; string websiteAdress = "http://baidu.com"; sendEmail(email, "找回密码", "尊敬的用户:你审请通过注册邮箱找回密码<br/>请点击链接重置密码:" + websiteAdress + "", "15733205015@163.com", "abc123");