Пример #1
0
        private static void SendSSLEmail(string account, string passwd, string server, M_EMail_Item mailMod)
        {
            M_EMail_SendLog logMod = new M_EMail_SendLog();
            B_EMail_SendLog logBll = new B_EMail_SendLog();

            logMod.ToAddress = mailMod.ToAddress;
            logMod.EmailID   = mailMod.ID;
            //--------------------------------------------------
            try
            {
            }
            catch (Exception ex) { logMod.Result = -1; logMod.ErrorMsg = ex.Message; }
            logBll.Insert(logMod);
        }
Пример #2
0
        private static void SendEmail(string account, string passwd, string server, M_EMail_Item mailMod)
        {
            M_EMail_SendLog logMod = new M_EMail_SendLog();
            B_EMail_SendLog logBll = new B_EMail_SendLog();

            logMod.ToAddress = mailMod.ToAddress;
            logMod.EmailID   = mailMod.ID;
            //--------------------------------------------------
            SmtpClient        client     = new SmtpClient(server, 25);
            NetworkCredential credential = new NetworkCredential(account, passwd);

            client.UseDefaultCredentials = true;
            client.EnableSsl             = false;
            client.Credentials           = credential.GetCredential(server, 25, "Basic");
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            //--------------------------------------------------
            try
            {
                MailMessage mail = new MailMessage();
                mail.SubjectEncoding = Encoding.UTF8;
                mail.BodyEncoding    = Encoding.UTF8;
                mail.IsBodyHtml      = true;
                mail.Priority        = MailPriority.Normal;
                mail.Subject         = mailMod.Subject;
                mail.Body            = mailMod.MailBody;

                if (!string.IsNullOrEmpty(mailMod.FromName))
                {
                    mail.From = new MailAddress(account, mailMod.FromName);
                }
                else
                {
                    mail.From = new MailAddress(account);
                }
                foreach (string file in mailMod.Attachment.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
                {
                    mail.Attachments.Add(new Attachment(function.VToP(file)));
                }
                mail.To.Add(new MailAddress(mailMod.ToAddress));
                //foreach (string email in mailMod.ToAddress.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
                //{
                //    mail.To.Add(new MailAddress(email));
                //}
                //foreach (string email in mailMod.CCAddress.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
                //{
                //    mail.CC.Add(email);
                //}
                //foreach (string email in mailMod.BCCAddress.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
                //{
                //    mail.Bcc.Add(email);
                //}
                client.Send(mail);
                logMod.Result = 1;
            }
            catch (Exception ex)
            {
                logMod.ErrorMsg = ex.Message;
                logMod.Result   = -1;
            }
            logBll.Insert(logMod);
        }