protected void Page_Load(object sender, EventArgs e) { string strErrorCode = string.Empty; string strUserInfo = string.Empty; string userName = string.Empty; string userTel = string.Empty; string[] strUserInfoList; if (Request["info"] != null) { if (Request["uinfo"] != null) { strUserInfo = Request["uinfo"].ToString().Trim(); strUserInfoList = strUserInfo.Split(new[] { "$$" }, StringSplitOptions.None); userName = strUserInfoList[0]; userTel = strUserInfoList[1]; } string strUrl = Request["info"].ToString(); try { string[] strList = strUrl.Split(new[] { "$$" }, StringSplitOptions.None); int intCustomerID = 0;//strList[0] string strCustomerID = string.Empty; strErrorCode = getErrorCode(strUrl); try { strCustomerID = DESEncrypt.Decrypt_DES(strList[0]); } catch (Exception ex) { } int.TryParse(strCustomerID, out intCustomerID); string strFileName = intCustomerID + "_" + strList[2]; byte[] sourcebytes = System.Text.Encoding.UTF8.GetBytes(strUrl); byte[] targetbytes = System.Text.Encoding.Convert(Encoding.Unicode, Encoding.UTF8, sourcebytes); string UTF8string = System.Text.Encoding.UTF8.GetString(targetbytes); } catch (Exception ex) { WebLog.WriteLog(string.Format("获取回传数据报错:{0}", ex.Message + ex.HelpLink + ex.InnerException + ex.Source + ex.StackTrace + ex.TargetSite), "Error"); } toList(strUrl, strErrorCode, userName, userTel); } }
public void toList(string strMessage, string strErrorCode, string UserName, string UserTel) { try { int intCustomerID = 0;//strList[0] //strUserName.Split(new[] { "cdc" }, StringSplitOptions.None); //string[] strList = System.Text.RegularExpressions.Regex.Split(strUserName, @"$#$", System.Text.RegularExpressions.RegexOptions.IgnoreCase); string[] strList = strMessage.Split(new[] { "$$" }, StringSplitOptions.None); string strLoginName = string.Empty; string strProductID = "000000"; SqlParameter[] parameters = { new SqlParameter("@CustomerID", SqlDbType.Int), new SqlParameter("@ProductID", SqlDbType.VarChar, 50), new SqlParameter("@ErrorMessage", SqlDbType.VarChar, 8000), new SqlParameter("@LoginName", SqlDbType.VarChar, 50), new SqlParameter("@isSuccessfull", SqlDbType.Int), new SqlParameter("@ErrorCode", SqlDbType.VarChar, 50), new SqlParameter("@IP", SqlDbType.VarChar, 50), new SqlParameter("@UserName", SqlDbType.VarChar, 50), new SqlParameter("@UserTel", SqlDbType.VarChar, 50) }; if (strList.Length > 3) { string strCustomerID = string.Empty; try { strCustomerID = DESEncrypt.Decrypt_DES(strList[0]); } catch (Exception ex) { } int.TryParse(strCustomerID, out intCustomerID); if (intCustomerID < 1) { try { strCustomerID = DESEncrypt.Decrypt_DES_Old(strList[0]); } catch (Exception ex) { } int.TryParse(strCustomerID, out intCustomerID); } int intSuccess = 0; int.TryParse(strList[3], out intSuccess); parameters[0].Value = intCustomerID; parameters[1].Value = strList[1]; parameters[2].Value = strMessage.Replace("'", "”").Replace("-", "——"); parameters[3].Value = strList[2]; parameters[4].Value = intSuccess; parameters[5].Value = strErrorCode; parameters[6].Value = getIP(strList[4]); parameters[7].Value = UserName; parameters[8].Value = UserTel; strLoginName = strList[2].Trim(); strProductID = strList[1].Trim(); } else { parameters[0].Value = -1; parameters[1].Value = "0000"; parameters[2].Value = "Error"; parameters[3].Value = strMessage; parameters[4].Value = 0; parameters[5].Value = "无"; parameters[7].Value = UserName; parameters[8].Value = UserTel; } DataSet ds = SqlHelperService.RunProcedure("UP_ActiveProductInfo_ADD", parameters, "ds"); if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(UserTel)) { HYTD.BLL.Call_WorkBillBLL wbll = new HYTD.BLL.Call_WorkBillBLL(); List <Models.Call_WorkBill> wModelList = wbll.GetCall_WorkBillList(intCustomerID, strProductID, strLoginName); if (wModelList != null && wModelList.Count < 1) { string strMessageNew = strMessage; if (strMessage.IndexOf("验证成功") > -1) { strMessageNew = strMessage.Substring(strMessage.IndexOf("验证成功") + 4); } CreateWorkBill(intCustomerID, strProductID, strLoginName, UserName, UserTel, strMessageNew); } } } catch (Exception ex) { WebLog.WriteLog(string.Format("添加数据库报错:{0}", ex.Message + ex.HelpLink + ex.InnerException + ex.Source + ex.StackTrace + ex.TargetSite), "Error"); } }
private void sendMail(string mailTo, string strToName, string mailCC, string mailBCC, string strTitle, string strBody, string strFilesPath) { intcounts++; string SmtpAddr = "192.168.10.31"; //System.Configuration.ConfigurationManager.AppSettings["SmtpAddr"];//邮箱服务器地址 string SendEmailAddr = "*****@*****.**"; //System.Configuration.ConfigurationManager.AppSettings["SendEmailAddr"];//发送邮件的邮箱地址 string SendEmailUserName = "******"; //System.Configuration.ConfigurationManager.AppSettings["SendEmailUserName"];//发送邮件的邮箱用户名 string SendEmailUserPwd = "123.com"; //System.Configuration.ConfigurationManager.AppSettings["SendEmailUserPwd"];//发送邮件的邮箱用户密码 MailMessage mail = new MailMessage(); mail.From = new MailAddress(SendEmailAddr, SendEmailUserName, System.Text.Encoding.GetEncoding("GB2312")); mail.To.Add(new MailAddress(mailTo, strToName, System.Text.Encoding.GetEncoding("GB2312"))); string[] strCCList = mailCC.Split(new[] { ",", ";", " " }, StringSplitOptions.RemoveEmptyEntries); string[] strBCCList = mailBCC.Split(new[] { ",", ";", " " }, StringSplitOptions.RemoveEmptyEntries); //抄送 foreach (var cc in strCCList) { string strtt = ""; if (cc.IndexOf("yangchao") > -1) { strtt = "项目经理"; } mail.CC.Add(new MailAddress(cc.Trim(), strtt, System.Text.Encoding.GetEncoding("GB2312"))); } //密送 foreach (var bcc in strBCCList) { mail.Bcc.Add(new MailAddress(bcc.Trim(), "", System.Text.Encoding.GetEncoding("GB2312"))); } mail.Subject = strTitle; mail.Body = strBody; mail.IsBodyHtml = true; mail.Priority = MailPriority.High; //附件 if (!string.IsNullOrEmpty(strFilesPath)) { System.Net.Mail.Attachment attachment1 = new System.Net.Mail.Attachment(strFilesPath);//添加附件 attachment1.Name = System.IO.Path.GetFileName(strFilesPath); attachment1.NameEncoding = System.Text.Encoding.GetEncoding("gb2312"); attachment1.TransferEncoding = System.Net.Mime.TransferEncoding.Base64; attachment1.ContentDisposition.Inline = true; attachment1.ContentDisposition.DispositionType = System.Net.Mime.DispositionTypeNames.Attachment; string cid = attachment1.ContentId;//关键性的地方,这里得到一个id数值 mail.Attachments.Add(attachment1); } //Attachment data = new Attachment(strFilesPath); //// Add time stamp information for the file. //ContentDisposition disposition = data.ContentDisposition; //disposition.CreationDate = System.IO.File.GetCreationTime(strFilesPath); //disposition.ModificationDate = System.IO.File.GetLastWriteTime(strFilesPath); //disposition.ReadDate = System.IO.File.GetLastAccessTime(strFilesPath); //// Add the file attachment to this e-mail message. //mail.Attachments.Add(data); SmtpClient smtp = new SmtpClient(SmtpAddr, 25); smtp.UseDefaultCredentials = false; smtp.EnableSsl = false; mail.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312"); mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312"); smtp.Credentials = new System.Net.NetworkCredential("caservice", SendEmailUserPwd, "hyitech.com"); try { smtp.Send(mail); smtp = null; Response.Write("[" + intcounts + "]" + strTitle + "发送完成" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss") + "<br />"); } catch (Exception ex) { Response.Write("[" + intcounts + "]" + strTitle + "发送失败<br />"); WebLog.WriteLog(ex.Message + ex.InnerException + ex.HelpLink + ex.Data + ex.Source + ex.StackTrace + ex.TargetSite, "sendMail"); } }
private void sendMail1(string mailTo, string strToName, string mailCC, string mailBCC, string strTitle, string strBody, string strFilesPath) { CDO.Message msg = new CDO.Message(); string passWord = "******"; string from = "*****@*****.**"; //string from = "hyitech\\caservice"; string server = "192.168.10.32";// "192.168.10.32"; //发件人 msg.From = from; //收件人 msg.To = mailTo; //抄送 if (mailCC.Trim().Length > 0) { msg.CC = mailCC; } //密送 if (mailBCC.Trim().Length > 0) { msg.BCC = mailBCC; } //标题 msg.Subject = strTitle; //正文 msg.TextBody = strBody; if (strFilesPath.Trim().Length > 0) { msg.AddAttachment(strFilesPath); } CDO.IConfiguration iConfig = msg.Configuration; ADODB.Fields fields = iConfig.Fields; //fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2; //fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = server; //fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = 25; //fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1; ////fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = true; //fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = "*****@*****.**"; //fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = passWord; fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2; fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = "*****@*****.**"; //修改这里,并保持发件人与这里的地址一致 fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = "*****@*****.**"; //修改这里 fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = "caservice"; //修改这里 fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = "123.com"; //修改这里 fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1; //value=0 代表Anonymous验证方式(不需要验证) //value=1 代表Basic验证方式(使用basic (clear-text) authentication. //The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.) //Value=2 代表NTLM验证方式(Secure Password Authentication in Microsoft Outlook Express) fields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value = 0x0804; fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = "192.168.10.32"; fields.Update(); try { msg.Send(); msg = null; Response.Write(strTitle + "发送完成<br />"); } catch (Exception ex) { WebLog.WriteLog(ex.Message + ex.InnerException + ex.HelpLink + ex.Data + ex.Source + ex.StackTrace + ex.TargetSite, "sendMail"); } }