public static void MailNotice_Send(int u_id, string u_name, string u_email, string temppwd, string template) { bool isReg = !string.IsNullOrEmpty(temppwd); MailServersInfo mailServer = DataAccess.MailServers_SelectRand(); string ml_title = "企业查询宝用户邮件认证"; string ml_type = "绑定邮箱认证"; MailClass mc = new MailClass(mailServer.ms_smtp, mailServer.ms_port, mailServer.ms_ssl, mailServer.ms_loginName, mailServer.ms_loginPwd); string bodyContent = string.Empty; var guid = Guid.NewGuid(); string code = guid.ToString().Substring(0, 4); CacheHelper.Cache_Store("Email_" + u_id, code, TimeSpan.FromMinutes(10)); bodyContent = string.Format("{0},您好:请点击如下链接,以完成您帐号的邮箱绑定,如无法点击请复制地址到浏览器中:<div style=\"font-Size:15px\">{1}</div>", u_email, "http://qiye.qianzhan.com/usercenter/SendEmail?code=" + code); //记录邮箱日志 MailClass.MailInfo mailInfo = new MailClass.MailInfo() { from = mailServer.ms_account, fromName = System.Configuration.ConfigurationManager.AppSettings["mailFromName"], to = u_email, toName = u_name, title = ml_title, body = bodyContent, isBodyHtml = true, userId = u_id.ToString(), ml_type = ml_type, sendComplete = new MailClass.OnSendComplete(OnSendComplete) }; mc.SendMailAsync(mailInfo); ////记录邮箱日志 //var maillog = new Users_MailLogInfo() //{ // ml_uid = Guid.NewGuid().ToString().Replace("-", "").Trim().Substring(0, 16), // ml_type = ml_type, // ml_to = u_email, // ml_toName = u_name, // ml_cc = string.Empty, // ml_title = ml_title, // ml_content = bodyContent, // ml_resend = 0, // ml_createTime = DateTime.Now, // ml_createUser = u_id.ToString(), // ml_from = mailServer.ms_account, // ml_fromName = System.Configuration.ConfigurationManager.AppSettings["MailFromName"] //}; //mc.SendMailAsync(mailInfo); }
public static void SendReportMail(string oc_code, string pdfPath, string toMail, string toName, string uId, OrgCompanyListInfo listInfo, MemoryStream ms) { // 邮件服务器ms_smtp|ms_port|ms_loginName|ms_loginPwd|ms_ssl //key="MailServer" value="mail.qianzhan.com|25|[email protected]|tech2018|0" string mailServerInfo = ConfigurationManager.AppSettings["MailServer"]; string[] mailServerArr = mailServerInfo.Split('|'); if (mailServerArr != null && mailServerArr.Length >= 5) { // 从配置文件获得邮件服务器信息 MailServersInfo mailServer = new MailServersInfo() { ms_account = mailServerArr[0], ms_smtp = mailServerArr[1], ms_port = int.Parse(mailServerArr[2]), ms_loginName = mailServerArr[3], ms_loginPwd = mailServerArr[4], ms_ssl = (mailServerArr[5] == "1") ? true : false }; MailClass mc = new MailClass(mailServer.ms_smtp, mailServer.ms_port, mailServer.ms_ssl, mailServer.ms_loginName, mailServer.ms_loginPwd); string templatePath = "/Templates/mail/ReportPDF.html"; string bodyContent = string.Empty; try { using (StreamReader sr = System.IO.File.OpenText(HostingEnvironment.MapPath(templatePath))) { bodyContent = sr.ReadToEnd(); sr.Close(); } } catch { } string companyName = listInfo.oc_name; string regNum = listInfo.oc_number; //string companyState = listInfo.oc_status ? "注销" : "正常"; string updateDate = listInfo.oc_updatetime.ToString("yyyy-MM-dd"); bodyContent = bodyContent.Replace("{companyName}", companyName).Replace("{regNum}", regNum).Replace("{updateDate}", updateDate); string ml_title = "企业信息报告-" + companyName; //string error; System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(ms, pdfPath); List <System.Net.Mail.Attachment> attachs = new List <System.Net.Mail.Attachment>(); // QZ.Common.SendEmailDelegate sed = new QZ.Common.SendEmailDelegate(mc.SendMail); attachs.Add(attach); MailClass.MailInfo mi = new MailClass.MailInfo() { attachs = attachs, from = mailServer.ms_account, fromName = System.Configuration.ConfigurationManager.AppSettings["MailFromName"], to = toMail, toName = toName, title = ml_title, body = bodyContent, isBodyHtml = true, ml_type = "企业信息报告", userId = uId, sendComplete = new MailClass.OnSendComplete(OnReportSendComplete) }; mc.SendMailAsync(mi); } }