コード例 #1
0
        static public void SendEmailNewProductToSupplier(Product product)
        {
            string        Key        = Settings.Keys.EMAIL_NEW_PRODUCT;
            int           TemplateId = GetEmailTemplateIdFromSettingKey(Key, "he-IL");
            EmailTemplate template   = TemplateId == 0 ? null : EmailTemplateController.GetItem(TemplateId);

            if (template != null)
            {
                string fromEmail    = template.FromEmail;
                string fromName     = template.FromName;
                string replyToEmail = template.ReplyToEmail;
                string replyToName  = template.ReplyToName;
                if (string.IsNullOrEmpty(fromEmail))
                {
                    fromEmail = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_FROM);
                }
                if (string.IsNullOrEmpty(fromName))
                {
                    fromName = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_FROM_NAME);
                }
                if (string.IsNullOrEmpty(replyToEmail))
                {
                    replyToEmail = Settings.GetSetting(Settings.Keys.ADMIN_EMAIL);
                }

                Dictionary <string, string> dictFieldHtml = new Dictionary <string, string>();
                dictFieldHtml.Add(@"PRODUCTNAME", product.ProductName);
                dictFieldHtml.Add(@"PRODUCTDESCIPTION", product.Description);
                dictFieldHtml.Add(@"PRODUCTCODE", product.ProductCode);

                string subject = EmailTemplateController.ReplaceSharpsInString(template.Subject, dictFieldHtml);

                string body = EmailTemplateController.ReplaceSharpsInString(template.Body, dictFieldHtml);

                string to = "";
                Query  q  = Query.New <AppSupplier>().Where(AppSupplier.Columns.IsDeleted, false);
                AppSupplierCollection col   = AppSupplierCollection.FetchByQuery(q);
                List <string>         lstTo = null;
                if (col != null)
                {
                    lstTo = col.Where(r => r.Email != null).Select(r => r.Email).ToList <string>();
                }
                if (to != "" || lstTo != null)
                {
                    System.Net.Mail.MailMessage message = EmailTemplateController.BuildMailMessage(
                        fromEmail, fromName, replyToEmail, replyToName,
                        to, template.CcList, template.BccList, subject, body, null, template.MailPriority, lstTo);
                    EmailTemplateController.Send(message, EmailLogController.EmailLogType.OnError, true);
                }
            }
        }