122121
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user