public static bool EnviarMail(String eOrigen,String eDestino,String asunto,String cueMensaje) { Boolean EstadoEnvio; MailMessage eMail = new MailMessage(); eMail.From = new MailAddress(eOrigen); eMail.To.Add(new MailAddress(eDestino)); eMail.Subject = asunto; eMail.IsBodyHTML = true; cueMensaje = cueMensaje.Replace("\r\n","<BR>"); eMail.Body = cueMensaje; eMail.Priority = MailPriority.normal; SmtpClIEnt clIEnteSMTP = new SmtpClIEnt(); try { clIEnteSMTP.Send(eMail); EstadoEnvio = true; } catch { EstadoEnvio = false; } return EstadoEnvio; }
在我的web.config中:
<mailSettings> <smtp from="iso@hmoore.com.ar"> <network host="174.120.190.6" port="25" username="iso@hmoore.com.ar" password="-----" defaultCredentials="true"/> </smtp> </mailSettings>解决方法 在ASP.NET应用程序中发送电子邮件时,有时您不希望用户体验减慢只是等待发送电子邮件.下面的代码示例是如何异步发送System.Net.Mail.MailMessage,以便当辅助线程发送电子邮件时,当前线程可以继续.
public static voID SendEmail(System.Net.Mail.MailMessage m){ SendEmail(m,true);}public static voID SendEmail(System.Net.Mail.MailMessage m,Boolean Async){ System.Net.Mail.SmtpClIEnt smtpClIEnt = null; smtpClIEnt = new System.Net.Mail.SmtpClIEnt("localhost"); if (Async) { SendEmailDelegate sd = new SendEmailDelegate(smtpClIEnt.Send); AsyncCallback cb = new AsyncCallback(SendEmailResponse); sd.BeginInvoke(m,cb,sd); } else { smtpClIEnt.Send(m); }}private delegate voID SendEmailDelegate(System.Net.Mail.MailMessage m);private static voID SendEmailResponse(IAsyncResult ar){ SendEmailDelegate sd = (SendEmailDelegate)(ar.AsyncState); sd.EndInvoke(ar);}
要使用它,只需使用System.Net.Mail.MailMessage对象调用SendEmail()方法即可.
总结以上是内存溢出为你收集整理的c# – ASP.NET从VStudio发送电子邮件在IIS中运行速度很快但速度非常慢全部内容,希望文章能够帮你解决c# – ASP.NET从VStudio发送电子邮件在IIS中运行速度很快但速度非常慢所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)