使用SMTP发送邮件太慢 [英] sending mail using smtp is too slow

查看:3230
本文介绍了使用SMTP发送邮件太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用SMTP发送邮件给用户。我能当用户点击发送按钮发送邮件,但它采取了近7秒内获得成功的消息,这是太长,用户可以点击按钮不止一次在不知不觉中,如果需要如此长的多用户。如果没有当用户点击提交按钮它采取不到一秒钟,但这的sendmail()方法与此的sendmail()其采取近7秒。什么可能是这个问题的原因是什么?

 从= ConfigurationManager.AppSettings.Get字符串(从);
        字符串PWD = ConfigurationManager.AppSettings.Get(密码);
        字符串客户端= ConfigurationManager.AppSettings.Get(客户);
        字符串端口= ConfigurationManager.AppSettings.Get(端口);
        串toMail = ConfigurationManager.AppSettings.Get(的toAddress);        的NetworkCredential LOGININFO =新的NetworkCredential(从,PWD);
        味精MAILMESSAGE新= MAILMESSAGE();
        SmtpClient smtpClient =新SmtpClient(客户端,int.Parse(端口));        msg.From =新的MailAddress(从);
        msg.To.Add(新MailAddress(toMail));
        msg.Subject =测试对象;
        msg.Body =测试邮件        msg.IsBodyHtml =真;        smtpClient.EnableSsl = TRUE;
        smtpClient.UseDefaultCredentials = FALSE;
        smtpClient.Credentials = LOGININFO;
        smtpClient.Send(MSG);


解决方案

发送邮件是异步的。

http://msdn.microsoft.com/ EN-US /库/ system.net.mail.smtpclient.aspx

I'm trying to send mail to user using SMTP. I'm able to send mail when the user clicks the send button, but it's taking almost 7 seconds to get success message to the user which is too long and the user may click the button more than once unknowingly if it takes so long. Without this sendmail() method when the user clicks the submit button it's taking less than a second but with this sendmail() its taking almost 7 seconds. What might be the reason for this issue?

        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);

解决方案

Send the mail asynchronously.

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

这篇关于使用SMTP发送邮件太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆