我想用SMTP发送邮件给用户。当用户点击发送按钮时,我可以发送邮件,但是向用户发送成功消息需要将近7秒的时间,而且用户可能会在不知情的情况下多次点击该按钮。如果没有这个方法,当用户点击提交按钮时,它会花费不到一秒钟的时间,但是这个sendmail()
需要花费将近7秒。这个问题可能是什么原因?使用smtp发送邮件太慢
string from = ConfigurationManager.AppSettings.Get("From");
string pwd = ConfigurationManager.AppSettings.Get("Password");
string Client= ConfigurationManager.AppSettings.Get("client");
string port = ConfigurationManager.AppSettings.Get("port");
string toMail = ConfigurationManager.AppSettings.Get("toaddress");
NetworkCredential loginInfo = new NetworkCredential(from,pwd);
MailMessage msg = new MailMessage();
SmtpClient smtpClient = new SmtpClient(client, int.Parse(port));
msg.From = new MailAddress(from);
msg.To.Add(new MailAddress(toMail));
msg.Subject = "Test Subject";
msg.Body = "Test Mail"
msg.IsBodyHtml = true;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = loginInfo;
smtpClient.Send(msg);
您应该提供一些代码,或许可以通过更改@ user3110493的代码来显示如何执行该操作。 – wonko79