You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
6.1 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//
using System.IO;
using MailAnalyzeTools.Models;
using System.Configuration;
using System.Threading;
using MailAnalyzeTools.Common;
using MailAnalyzeTools.Logic;
namespace MailAnalyzeTools
{
public partial class frmAnalyzeMail
{
private db_sendmail_Logic m_db_sendmail_Logic;
private static List<string> m_ListSendDZDNPath;
private void InitSendRecDzdnPath()
{
if (m_ListSendDZDNPath!=null)
{
return;
}
DataTable dt;
m_ListSendDZDNPath = new List<string>();
string sql = @"select cast(attachment as varchar(200)) as attachment from t_op_seae_edi_send_mailbox m where DATEDIFF(DAY,m.order_senddate , GETDATE())<2 ";
try
{
dt = DbHelperSQL.QueryTable(sql);
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
string dzlj = dr["attachment"] == DBNull.Value ? "" : dr["attachment"].ToString();
if (dzlj.Length>0 &&m_ListSendDZDNPath.Contains(dzlj)==false)
{
m_ListSendDZDNPath.Add(dzlj);
}
}
}
}
catch (Exception ex )
{
throw;
}
}
/// <summary>
///
/// </summary>
private void sendmailAction()
{
DataTable dt = m_db_sendmail_Logic.GetToSendmail();
if (dt == null || dt.Rows.Count < 1)
return;
int icount = dt.Rows.Count;
Mailconfig mcg = frmMailSet.MailconfigSet();
//smart 邮箱无法发送邮件....
//string SMTPHost = mcg.SmtpMailServer_Addr;//"smptcom.263xmail.com";
//string SMpTPort = mcg.SmtpMailServer_Port.ToString(); //"25";
//string SMTPuser = mcg.MailAddress;//"dev003@dongshengsoft.com";
//string SMTPpass = mcg.MailPassWord;// "ds20040201";
//string SMTPHost = "smtp.263.net";//"smptcom.263xmail.com";
//string SMpTPort = "25";
//string SMTPuser = "dev003@dongshengsoft.com";
//string SMTPpass = "carey2017";
//
string SMTPHost = "smtpcom.263xmail.com";//"smptcom.263xmail.com";
string SMpTPort = "465";
string SMTPuser = "admin@dongshengsoft.com";
string SMTPpass = "ds!@#)(*";
bool chkSSL = mcg.SmtpMailServer_SSL == 1 ? true : false;
for (int i = 0; i < icount; i++)
{
string mail_id = Guid.NewGuid().ToString("N");
try
{
string from;
string fromUername;
//初始化字典
InitSendRecDzdnPath();
string fromSMTPuser;//发件服务器验证的邮件地址
string fromSMTPpass;//发件服务器验证需要的密码
mail_id = dt.Rows[i]["mail_id"].ToString();
fromUername = dt.Rows[i]["sender"].ToString();
from = dt.Rows[i]["sender_address"]==DBNull.Value? "admin@dongshengsoft.com" : dt.Rows[i]["sender_address"].ToString();
if (string.IsNullOrEmpty(from))
{
LogHelper.WriteLog("邮件发送者邮件地址为空:", fromUername);
}
if (dt.Rows[i]["use_defaultmail_send"] == DBNull.Value || bool.Parse(dt.Rows[i]["use_defaultmail_send"].ToString()) == false)
{
fromSMTPuser = from;
fromSMTPpass = dt.Rows[i]["sender_password"].ToString();
}
else
{
fromSMTPuser = SMTPuser;
//fromUername = mcg.MailDisplayName;
fromSMTPpass = SMTPpass;
}
string to = dt.Rows[i]["send_to"].ToString();//"careygege@126.com";
string cc = dt.Rows[i]["cc_to"].ToString();//"careygege@126.com";
bool isbodyHtml = dt.Rows[i]["ishtml"] == DBNull.Value ? false : bool.Parse(dt.Rows[i]["ishtml"].ToString());
string Subject = dt.Rows[i]["subject"].ToString();
string filePath = dt.Rows[i]["attachment"].ToString();
//已经包含则忽略,不再继续发送
if (!string.IsNullOrEmpty(filePath)&&m_ListSendDZDNPath.Contains(filePath))
{
LogHelper.WriteLog("屏蔽重复发邮件:", Subject);
continue;
}
string Body = dt.Rows[i]["mail_content"].ToString();
string errinfo;
bool isok = SendmaillTool.sendmail(from, fromUername, to, cc, isbodyHtml, Subject, Body, filePath, SMTPHost, SMpTPort, fromSMTPuser, fromSMTPpass, out errinfo);
if (isok)
{
m_db_sendmail_Logic.MoveToSendedMailTable(errinfo, mail_id);
//加入字典防止重复发送
m_ListSendDZDNPath.Add(filePath);
}
else
{
m_db_sendmail_Logic.UpdateSendmailError(errinfo, mail_id);
LogHelper.WriteLog("BC邮件发送失败", errinfo+Subject);
}
}
catch (Exception ex)
{
LogHelper.WriteLog( "sendmail action 发生错误:", ex.Message);
m_db_sendmail_Logic.UpdateSendmailError(ex.Message, mail_id);
}
}
}
}
}