Beispiel #1
0
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="sub">邮件主题</param>
        /// <param name="message">邮件内容</param>
        /// <param name="mailInfo">发送人实体类</param>
        public static void SendMail(string sub, string message, MailInfo mailInfo)
        {
            SmtpClient smtp = new SmtpClient
            {
                DeliveryMethod = SmtpDeliveryMethod.Network,
                EnableSsl      = false,
                Host           = mailInfo.MailHost,
                Port           = 0x19,
                Credentials    = new NetworkCredential(mailInfo.UserID, CoderMaker.Decode(mailInfo.UserPwd))
            };
            MailMessage mm = new MailMessage
            {
                Priority = MailPriority.High,
                From     = new MailAddress(mailInfo.UserID, mailInfo.UserName, Encoding.GetEncoding(0x3a8))
            };

            for (int i = 0; i < mailInfo.ToUser.Length; i++)
            {
                try
                {
                    mm.To.Add(new MailAddress(mailInfo.ToUser[i].UserID, mailInfo.ToUser[i].UserName, Encoding.GetEncoding(936)));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            mm.Subject         = sub;
            mm.SubjectEncoding = Encoding.GetEncoding(0x3a8);
            mm.IsBodyHtml      = true;
            mm.BodyEncoding    = Encoding.GetEncoding(0x3a8);
            mm.Body            = message;
            try
            {
                smtp.Send(mm);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        //Json配置文件
        //"MailInfo": {
        //    "MailHost": "smtp.qiye.163.com",
        //    "IsSendEmail": true,
        //    "ToUser": [ { "UserID": "*****@*****.**", "UserName": "******" }, { "UserID": "*****@*****.**", "UserName": "******" } ],
        //    "UserID": "*****@*****.**",
        //    "UserPwd": "eHVzaGVuKzI2MA==",
        //    "UserName": "******"
        //}

        /// <summary>
        /// 发送邮件信息
        /// </summary>
        /// <param name="sub"></param>
        /// <param name="msg"></param>
        public static void SendMailInfo(string sub, string msg)
        {
            try
            {
                MailInfo mailInfo = new MailInfo();
                //mailInfo = CommonConfig.Instance.Model().MailInfo;
                new Thread(new ThreadStart(delegate
                {
                    try
                    {
                        MailHelper.SendMail(sub, msg, mailInfo);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.ErrorLoger.Error("SendMail1:" + ex.Message);
                    }
                })
                           ).Start();
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("SendMail2:" + ex.Message);
            }
        }