コード例 #1
0
        protected void SendMail(MailMsg msg, Dictionary<string, string> mailTo)
        {
            try
            {
                var business = new EmailSettingBusinessLogic();
                var setting = business.GetFirstEmailSetting();

                if (setting != null)
                {
                    var message = new MailMessage();
                    {
                        if (EPATheme.Current!=null && EPATheme.Current.Themes!= null && !string.IsNullOrEmpty(EPATheme.Current.Themes.WebsiteName))
                        {
                            message.From = new MailAddress(setting.Sender, EPATheme.Current.Themes.WebsiteName);
                        }
                        else
                        {
                            message.From = new MailAddress(setting.Sender, "ePosAnytime");
                        }

                        foreach (var pair in mailTo)
                        {
                            message.To.Add(new MailAddress(pair.Key, pair.Value));
                        }
                        message.Subject = msg.Subject;
                        message.Body = msg.Body;
                        message.IsBodyHtml = true;
                    }

                    // smtp settings
                    var smtp = new System.Net.Mail.SmtpClient();
                    {
                        //smtp.Host = "smtp.gmail.com";
                        smtp.Host = setting.Host;
                        //smtp.Port = 587;
                        smtp.Port = setting.Port;
                        //smtp.EnableSsl = true;
                        smtp.EnableSsl = setting.EnableSsl;
                        //smtp.Timeout = 20000;
                        smtp.Timeout = setting.Timeout;

                        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                        smtp.Credentials = new NetworkCredential(setting.AuthenticationUser, setting.AuthenticationPassword);
                    }
                    // Passing values to smtp object
                    //smtp.Send(message.FromAddress, message.ToAddress, message.Subject, message.Body);
                    smtp.Send(message);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
        }
コード例 #2
0
        public void SendMailOrder(MailMsg msg, string mailToAddr, string mailToName, string mailFromAddr, string mailFromName, string mailFromSubj)
        {
            //SendMail(msg, new Dictionary<string, string>() { { msg.ToAddress, msg.ToDisplayName } });

            try
            {
                var businessTemp = new EmailSettingBusinessLogic();
                var setting = businessTemp.GetFirstEmailSetting();
                if (setting != null)
                {
                    var message = new MailMessage();
                    {
                        message.From = new MailAddress(mailFromAddr, mailFromName);
                        message.To.Add(new MailAddress(mailToAddr, mailToName));
                        message.Subject = mailFromSubj;
                        message.Body = msg.Body;
                        message.IsBodyHtml = true;
                    }

                    var smtp = new System.Net.Mail.SmtpClient();
                    {
                        //smtp.Host = "smtp.gmail.com";
                        smtp.Host = setting.Host;
                        //smtp.Port = 587;
                        smtp.Port = setting.Port;
                        //smtp.EnableSsl = true;
                        smtp.EnableSsl = setting.EnableSsl;
                        //smtp.Timeout = 20000;
                        smtp.Timeout = setting.Timeout;

                        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                        smtp.Credentials = new NetworkCredential(setting.AuthenticationUser, setting.AuthenticationPassword);
                    }
                    // Passing values to smtp object
                    //smtp.Send(message.FromAddress, message.ToAddress, message.Subject, message.Body);
                    smtp.Send(message);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
        }