@{ var customerName = "验证码"; var customerEmail = Request["email"]; var customerRequest = "尊敬的用户,您好!您在获取的验证码是:" + emailCode; var errorMessage = "发送失败,请检查邮箱是否正确!"; try { WebMail.SmtpServer = "smtp.qq.com"; WebMail.SmtpPort = "465"; WebMail.UserName = "1030272178@qq.com"; WebMail.Password = "password"; WebMail.From = "1030272178@qq.com"; WebMail.EnableSsl = true; WebMail.Send(to: customerEmail, subject: ""+ customerName, body: customerRequest ); errorMessage = "邮件发送成功,若未收到邮件,请检查您邮箱设置! " + ";" + emailCode; } catch (Exception ex ) { errorMessage = ex.Message; } @errorMessage; }
用25端口可以发送 465端口不行 telnet smtp.qq.com 465 是通的
换587端口解决问题