日期:2014-05-17 浏览次数:20476 次
//发起ajax请求发送邮件和短信 $.ajax({ type: "POST", contentType: "application/json", url: "SendEmailMethod.aspx/SendMail", data: "{pw:'" + Math.random() + "',mailSubject:'" + mailSubject + "',mailSender:'" + mailSender + "',mailToList:'" + mailToList + "',mailCcList:'" + mailCcList + "',mailContent:'" + mailContent + "'}", dataType: 'json', success: function (result) { closeWaitingDialog("showWaiting"); //关闭等待提示框 showCustomDialog("showResult", result.d); //显示操作结果对话框 } });
/// <summary> /// 发送邮件服务器端方法并手动输入的手机号码发送短信 /// </summary> /// <param name="mailSubject">邮件主题</param> /// <param name="mailSender">邮件发送人地址</param> /// <param name="mailToList">接收人列表</param> /// <param name="mailCcList">抄送人列表</param> /// <param name="mailContent">邮件内容</param> /// <param name="mobileList">手机号列表</param> /// <returns></returns> [WebMethod] public static bool SendMail(string mailSubject, string mailSender, string mailToList, string mailCcList, string mailContent, string mobileList) { try { SendMail mail = new SendMail(); //收件人列表 mail.MailToList = new List<string>(); foreach (string mailTo in mailToList.Split(new char[] { ';', ',' })) { if (mailTo.Trim() != string.Empty) { mail.MailToList.Add(mailTo); } } //抄送人列表 mail.MailCcList = new List<string>(); foreach (string mailCc in mailCcList.Split(new char[] { ';', ',' })) { if (mailCc.Trim() != "") { mail.MailCcList.Add(mailCc); } } //邮件发送类的发件人,主题,主体内容等 mail.MailSender = mailSender; mail.MailSubject = mailSubject; mail.MailContent = mailContent; //附件文件必须是服务器上面的地址 //也就是如果从本地电脑读取文件则需要上传到服务器 //附件功能暂时不使用,需要时再启用 //mail.MailAttachmentList = new List<string>(); //foreach (string attachment in mailAttachmentList.Split(new char[] { ';', ',' })) //{ // if (attachment.Trim() != string.Empty) // { // mail.MailAttachmentList.Add(attachment.Trim()); // } //} //开始发送邮件 mail.Send(); //邮件发送成功后才开始将短信内容存储到后台服务器中 string[] mobiles = mobileList.Split(new char[] { ';', ',' }); IRepository<SendingMessage> rep = new SendingMessageRepository(); foreach (string mobile in mobiles) { rep.Add(new SendingMessage { MessageContent = mailCont