This commit is contained in:
jackchenyang
2024-05-17 23:21:21 +08:00
parent fe82692030
commit 6187cd3f47
9 changed files with 365 additions and 224 deletions
-1
View File
@@ -161,7 +161,6 @@
<Compile Include="PublicInfo\FileControl\FileControl_DomesticStandardsService.cs" />
<Compile Include="PublicInfo\FileControl\FileControl_ForeignStandardsService.cs" />
<Compile Include="PublicInfo\WPQ\WPQListService.cs" />
<Compile Include="SendEmailService.cs" />
<Compile Include="SessionName.cs" />
<Compile Include="SoftRegeditService.cs" />
<Compile Include="SQLHelper.cs" />
+76 -59
View File
@@ -46,77 +46,92 @@ namespace FineUIPro.Web.common
mailFrom = ps.EmailYx;
}
MailMessage email = new MailMessage();
//MailAddress emailFrom = new MailAddress(mailFrom);
//MailMessage email = new MailMessage();
////MailAddress emailFrom = new MailAddress(mailFrom);
//发件人
email.From = new MailAddress(mailFrom, ps.EmailYx);//发件人地址
////发件人
//email.From = new MailAddress(mailFrom, ps.EmailYx);//发件人地址
//收件人
if (mailTo != null && mailTo.Length > 0)
{
foreach (string send in mailTo)
{
if (!String.IsNullOrEmpty(send))
{
email.To.Add(send);
}
}
}
////收件人
//if (mailTo != null && mailTo.Length > 0)
//{
// foreach (string send in mailTo)
// {
// if (!String.IsNullOrEmpty(send))
// {
// email.To.Add(send);
// }
// }
//}
//加抄送
if (mailCC != null && mailCC.Length > 0)
{
////加抄送
//if (mailCC != null && mailCC.Length > 0)
//{
foreach (string cc in mailCC)
{
if (!String.IsNullOrEmpty(cc))
{
email.CC.Add(cc);
}
}
}
// foreach (string cc in mailCC)
// {
// if (!String.IsNullOrEmpty(cc))
// {
// email.CC.Add(cc);
// }
// }
//}
//主题
email.Subject = mailSubject;
//内容
email.Body = mailBody;
//附件
if (!string.IsNullOrEmpty(mailAttch))
{
string[] attachments = mailAttch.Split(';');
foreach (string file in attachments)
{
System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
//为附件添加发送时间
System.Net.Mime.ContentDisposition disposition = attach.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
//添加附件
email.Attachments.Add(attach);
}
}
////主题
//email.Subject = mailSubject;
////内容
//email.Body = mailBody;
////附件
//if (!string.IsNullOrEmpty(mailAttch))
//{
// string[] attachments = mailAttch.Split(';');
// foreach (string file in attachments)
// {
// System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
// //为附件添加发送时间
// System.Net.Mime.ContentDisposition disposition = attach.ContentDisposition;
// disposition.CreationDate = System.IO.File.GetCreationTime(file);
// disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
// disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
// //添加附件
// email.Attachments.Add(attach);
// }
//}
//优先级
email.Priority = (mailPriority == "High") ? System.Net.Mail.MailPriority.High : System.Net.Mail.MailPriority.Normal;
//内容编码、格式
email.BodyEncoding = System.Text.Encoding.UTF8;
email.IsBodyHtml = true;
//email.Priority = (mailPriority == "High") ? System.Net.Mail.MailPriority.High : System.Net.Mail.MailPriority.Normal;
////内容编码、格式
//email.BodyEncoding = System.Text.Encoding.UTF8;
//email.IsBodyHtml = true;
//SMTP服务器
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(ps.EmailFwq);
client.UseDefaultCredentials = true;
//验证(Credentials 凭证)
client.Credentials = new System.Net.NetworkCredential(mailFrom, ps.EmailPass);
//处理待发的电子邮件的方法 (Delivery 发送,传输)
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
//System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(ps.EmailFwq);
//client.EnableSsl = false;
//client.UseDefaultCredentials = true;
////验证(Credentials 凭证)
//client.Credentials = new System.Net.NetworkCredential(mailFrom, ps.EmailPass);
////处理待发的电子邮件的方法 (Delivery 发送,传输)
//client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
try
{
mail.From = ps.EmailYx;
mail.To = string.Join(",", mailTo);
mail.Subject = mailSubject;
mail.BodyFormat = System.Web.Mail.MailFormat.Html;
mail.Body =mailBody;
mail.Cc = string.Join(",", mailCC);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ps.EmailYx);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ps.EmailPass);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport",ps.EmailDk);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
System.Web.Mail.SmtpMail.SmtpServer = ps.EmailFwq;
System.Web.Mail.SmtpMail.Send(mail);
BLL.ErrLogInfo.WriteLog("开始发送邮件");
//发送邮件
client.Send(email);
//client.Send(email);
BLL.ErrLogInfo.WriteLog("发送中...");
if (mailTo != null && mailTo.Length > 0)
{
foreach (string send in mailTo)
@@ -140,6 +155,7 @@ namespace FineUIPro.Web.common
}
catch (Exception ex)
{
BLL.ErrLogInfo.WriteLog(ex, "发送邮件失败");
if (mailTo != null && mailTo.Length > 0)
{
List<Email_SendLog> ss = new List<Email_SendLog>();
@@ -155,6 +171,7 @@ namespace FineUIPro.Web.common
newSendEmail.EmailName = send;
newSendEmail.EmailStatus = "发送失败";
newSendEmail.CreateTime = DateTime.Now;
newSendEmail.ErrorMsg = ex.Message;
newSendEmail.CreateName = "sys";
BLL.Email_Send.Email_SendLogService.AddEmail_SendLog(newSendEmail);
}
-92
View File
@@ -1,92 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace BLL
{
public class SendEmailService
{
/// <summary>
///
/// </summary>
/// <param name="sender">发件人</param>
/// <param name="receiver">收件人</param>
/// <param name="title">标题</param>
/// <param name="content">内容</param>
/// <param name="FulPath">附件地址</param>
/// <param name="passWord">密码</param>
/// <returns></returns>
public static bool SendEmail(string sender, string receiver, string title, string content, string FulPath, string passWord)
{
bool IsSend = true;
MailMessage mailObject = new MailMessage();
string fromAddress = sender; //发件人
MailAddress mayAddress = new MailAddress(fromAddress);
mailObject.SubjectEncoding = System.Text.Encoding.UTF8;
mailObject.BodyEncoding = System.Text.Encoding.UTF8;
//设置邮件的收件人
string address = "";
string[] mailNames = (receiver + ";").Split(';');
foreach (string name in mailNames)
{
if (name != string.Empty)
{
if (name.IndexOf('<') > 0)
{
address = name.Substring(name.IndexOf('<') + 1).Replace('>', ' ');
}
else
{
address = name.Substring(name.IndexOf('<') + 1).Replace('>', ' ');
}
mailObject.To.Add(new MailAddress(address));//收件人
}
}
mailObject.From = mayAddress;
mailObject.Subject = title;// "标题";
mailObject.Body = content;//"内容";
mailObject.IsBodyHtml = false;
//设置邮件的附件,将在客户端选择的附件先上传到服务器保存一个,然后加入到mail中
//设置邮件的附件,将在客户端选择的附件先上传到服务器保存一个,然后加入到mail中
if (!String.IsNullOrEmpty(FulPath))
{
mailObject.Attachments.Add(new Attachment(FulPath));
mailObject.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
}
SmtpClient client;
client = new SmtpClient("smtp." + fromAddress.Substring(fromAddress.LastIndexOf("@") + 1));
client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
client.Timeout = 60000;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(fromAddress, passWord);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
client.Send(mailObject);
return IsSend;
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
return !IsSend;
}
}
}
}