错误异常>开发语言>C#
项目中,需要通过程序批量发送通知邮件给用户,在页面中调用发送邮件的程序的时候报错:
Asp.Net 发送邮件的代码如下:
public class EMailHelper { #region IEMailHelper 成员 public static bool Send(string smtpServer, string emailAccount, string password, MailAddress emailFrom, MailAddress emailTo, string subject, string emailBody, params string [] attachments) { //生成一个 使用SMTP发送邮件的客户端对象 System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(smtpServer); //表示以当前登录用户的默认凭据进行身份验证 client.UseDefaultCredentials = true; //包含用户名和密码 client.Credentials = new System.Net.NetworkCredential(emailAccount, password); //指定如何发送电子邮件。 //Network 电子邮件通过网络发送到 SMTP 服务器。 //PickupDirectoryFromIis 将电子邮件复制到挑选目录,然后通过本地 Internet 信息服务 (IIS) 传送。 //SpecifiedPickupDirectory 将电子邮件复制到 SmtpClient.PickupDirectoryLocation 属性指定的目录,然后由外部应用程序传送。 client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; //建立邮件对象 System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(emailFrom, emailTo); message.Subject = subject; message.Body = emailBody; //定义邮件正文,主题的编码方式 message.BodyEncoding = System.Text.Encoding.UTF8; message.SubjectEncoding = System.Text.Encoding.UTF8; //获取或设置一个值,该值指示电子邮件正文是否为 HTM
在相应aspx页面里面单独启用异步操作就可以,有两种方式
一、在页面内配置 ,重点是:Async="true"
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="*" Inherits="*" Async="true"%>
二、在程序里面配置
暂时找不到代码了