static public void SendMailNoOffersToAdmin(AppUserUI user, DateTime StartBidDate, List <BidProductUI> products, string subject, string body)
        {
            string fromEmail    = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_FROM);
            string fromName     = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_FROM_NAME);
            string replyToEmail = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_REPLYTO);
            string replyToName  = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_REPLYTO_NAME);
            string toList       = Settings.GetSetting(Settings.Keys.ADMIN_EMAIL);

            Dictionary <string, string> dictFieldHtml = new Dictionary <string, string>();

            dictFieldHtml.Add(@"{NAME}", (user.FirstName + @" " + user.LastName).Trim());
            dictFieldHtml.Add(@"{PHONE}", user.Phone);
            dictFieldHtml.Add(@"{CITY}", user.CityName);
            string str = "";

            foreach (BidProductUI item in products)
            {
                str += item.Amount + " " + item.ProductName + @" <br /> ";
            }
            dictFieldHtml.Add(@"{PRODUCTS}", str);
            dictFieldHtml.Add(@"{DATE}", StartBidDate.ToShortDateString());
            dictFieldHtml.Add(@"{TIME}", StartBidDate.ToShortTimeString());


            foreach (string key in dictFieldHtml.Keys.ToList())
            {
                dictFieldHtml[key] = dictFieldHtml[key].ToHtml().Replace("\n", @"<br />");
            }
            body = EmailTemplateController.ReplaceSharpsInString(body, dictFieldHtml);

            System.Net.Mail.MailMessage message = EmailTemplateController.BuildMailMessage(
                fromEmail, fromName, replyToEmail, replyToName, toList, null, null, subject, body, null, System.Net.Mail.MailPriority.Normal);
            EmailTemplateController.Send(message, EmailLogController.EmailLogType.OnError, true);
        }
Пример #2
0
    protected void btnSend_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }
        string fileName = "";

        if (FUploadImage.FileName != "" && !IsAcceptedImageExtension(FUploadImage.FileName))
        {
            Master.MessageCenter.DisplayErrorMessage(ContactStrings.GetText("InvalidExtension"));
            return;
        }
        else
        {
            fileName = Server.MapPath(Path.Combine(Settings.Keys.CONTACT_FOLDER, FUploadImage.FileName));
            try
            {
                FUploadImage.SaveAs(fileName);
            }

            catch (Exception) { }
        }
        bool   result       = false;
        string toList       = Settings.GetSetting(Settings.Keys.ADMIN_EMAIL);
        string fromEmail    = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_FROM);
        string fromName     = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_FROM_NAME);
        string replyToEmail = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_REPLYTO);
        string replyToName  = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_REPLYTO_NAME);
        string subject      = ContactStrings.GetText("ContactTitle");
        string body         = "<table>" +
                              "<tr><td>" + ContactStrings.GetText("FirstName") + "</td><td>" + txtFirstName.Text + "</td></tr>" +
                              "<tr><td>" + ContactStrings.GetText("Email") + "</td><td>" + txtEmail.Text + "</td></tr>" +
                              "<tr><td>" + ContactStrings.GetText("Phone") + "</td><td>" + txtPhone.Text + "</td></tr>" +
                              "<tr><td>" + ContactStrings.GetText("ContactType") + "</td><td>" + ddlContactType.SelectedItem.Text + "</td></tr>" +
                              "<tr><td>" + ContactStrings.GetText("ContactDetails") + "</td><td>" + txtContactDetails.Text + "</td></tr>" +
                              "</table>";

        System.Net.Mail.MailMessage message = EmailTemplateController.BuildMailMessage(
            fromEmail, fromName, replyToEmail, replyToName,
            toList, null, null, subject, body, new string[] { fileName }, System.Net.Mail.MailPriority.Normal);
        result = EmailTemplateController.Send(message, EmailLogController.EmailLogType.OnError, true);

        if (result == true)
        {
            txtEmail.Text          = "";
            txtFirstName.Text      = "";
            txtContactDetails.Text = "";
            txtPhone.Text          = "";

            Master.MessageCenter.DisplaySuccessMessage(ContactStrings.GetText(@"MessageSend"));
        }
        else
        {
            Master.MessageCenter.DisplayErrorMessage(ContactStrings.GetText(@"Error"));
        }
    }
Пример #3
0
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);

            JObject inputData = null;

            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }
            string name    = inputData.Value <string>(@"name") ?? "";
            string email   = inputData.Value <string>(@"email") ?? "";
            string phone   = inputData.Value <string>(@"phone") ?? "";
            string content = inputData.Value <string>(@"content") ?? "";

            Response.ContentType = @"application/json";

            using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
            {
                using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                {
                    try
                    {
                        string subject = GlobalStrings.GetText("ContactUsSubject", new CultureInfo("he-IL"));
                        string body    = GlobalStrings.GetText("Email", new CultureInfo("he-IL")) + " : " + email + "<br>" +
                                         GlobalStrings.GetText("Phone", new CultureInfo("he-IL")) + " : " + phone + "<br>" +
                                         GlobalStrings.GetText("Content", new CultureInfo("he-IL")) + " : " + content + "<br>";
                        string AdminEmail   = Settings.GetSetting(Settings.Keys.ADMIN_EMAIL);
                        string fromEmail    = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_FROM);
                        string replyToEmail = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_REPLYTO);
                        string fromName     = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_FROM_NAME);
                        string replyToName  = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_REPLYTO_NAME);
                        System.Net.Mail.MailMessage message = EmailTemplateController.BuildMailMessage(
                            fromEmail, fromName, replyToEmail, replyToName,
                            AdminEmail, null, null, subject, body, null, null);
                        EmailTemplateController.Send(message, EmailLogController.EmailLogType.OnError, true);
                    }
                    catch (Exception) { }

                    jsonWriter.WriteStartObject();
                    jsonWriter.WriteEndObject();
                }
            }
        }
        static public void SendPasswordRecoveryMailForUser(User user, string RecoveryKey, string LangCode)
        {
            UserProfile profile = UserProfile.FetchByID(user.UserId);

            string        Key        = Settings.Keys.EMAIL_TEMPLATE_USER_FORGOT_PASSWORD;
            int           TemplateId = GetEmailTemplateIdFromSettingKey(Key, string.IsNullOrEmpty(LangCode) ? profile.DefaultLangCode : LangCode);
            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;
                string toList       = template.ToList + @";" + user.Email;
                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.DEFAULT_EMAIL_REPLYTO);
                }
                if (string.IsNullOrEmpty(replyToName))
                {
                    replyToName = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_REPLYTO_NAME);
                }

                Dictionary <string, string> dictFieldHtml = new Dictionary <string, string>();
                dictFieldHtml.Add(@"USERFIRSTNAME", profile.FirstName);
                dictFieldHtml.Add(@"USERLASTNAME", profile.LastName);
                dictFieldHtml.Add(@"USERFULLNAME", (profile.FirstName + @" " + profile.LastName).Trim());
                dictFieldHtml.Add(@"USEREMAIL", user.Email);
                dictFieldHtml.Add(@"PASSWORDKEY", System.Net.WebUtility.HtmlEncode(RecoveryKey));

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

                //foreach (string key in dictFieldHtml.Keys)
                //{
                //    dictFieldHtml[key] = dictFieldHtml[key].ToHtml().Replace("\n", @"<br />");
                //}
                string body = EmailTemplateController.ReplaceSharpsInString(template.Body, dictFieldHtml);

                System.Net.Mail.MailMessage message = EmailTemplateController.BuildMailMessage(
                    fromEmail, fromName, replyToEmail, replyToName,
                    toList, template.CcList, template.BccList, subject, body, null, template.MailPriority);
                EmailTemplateController.Send(message, EmailLogController.EmailLogType.OnError, true);
            }
        }
        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);
                }
            }
        }
        static public void SendWelcomeMailWithVerificationForAppUser(AppUser user, string VerifyKey, string LangCode)
        {
            string        Key        = Settings.Keys.EMAIL_TEMPLATE_NEW_APPUSER_WELCOME_VERIFY_EMAIL;
            int           TemplateId = GetEmailTemplateIdFromSettingKey(Key, string.IsNullOrEmpty(LangCode) ? user.LangCode : LangCode);
            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;
                string toList       = template.ToList + @";" + user.Email;
                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.DEFAULT_EMAIL_REPLYTO);
                }
                if (string.IsNullOrEmpty(replyToName))
                {
                    replyToName = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_REPLYTO_NAME);
                }

                Dictionary <string, string> dictFieldHtml = new Dictionary <string, string>();
                dictFieldHtml.Add(@"USERFIRSTNAME", user.FirstName);
                dictFieldHtml.Add(@"USERLASTNAME", user.LastName);
                dictFieldHtml.Add(@"USERFULLNAME", (user.FirstName + @" " + user.LastName).Trim());
                dictFieldHtml.Add(@"USEREMAIL", user.Email);
                dictFieldHtml.Add(@"PASSWORDKEY", VerifyKey);

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

                foreach (string key in dictFieldHtml.Keys)
                {
                    dictFieldHtml[key] = dictFieldHtml[key].ToHtml().Replace("\n", @"<br />");
                }
                string body = EmailTemplateController.ReplaceSharpsInString(template.Body, dictFieldHtml);

                System.Net.Mail.MailMessage message = EmailTemplateController.BuildMailMessage(
                    fromEmail, fromName, replyToEmail, replyToName,
                    toList, template.CcList, template.BccList, subject, body, null, template.MailPriority);
                EmailTemplateController.Send(message, EmailLogController.EmailLogType.OnError, true);
            }
        }
        static public void SendNewBidToSupplier(BidMessage msg)
        {
            string        Key        = Settings.Keys.EMAIL_TEMPLATE_SUPPLIER_NEW_BID;
            AppSupplier   supplier   = SupplierUI.FetchByID(msg.SupplierId);
            int           TemplateId = GetEmailTemplateIdFromSettingKey(Key, supplier.LangCode);
            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.DEFAULT_EMAIL_REPLYTO);
                }
                if (string.IsNullOrEmpty(replyToName))
                {
                    replyToName = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_REPLYTO_NAME);
                }

                Dictionary <string, string> dictFieldHtml = new Dictionary <string, string>();
                dictFieldHtml.Add(@"BIDID", msg.BidId.ToString());

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

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

                bool   isProduction = Convert.ToBoolean(AppConfig.GetString(@"IsProduction", @"false"));
                string emailTo      = isProduction ? supplier.Email:AppConfig.GetString(@"DevMailAddress", @"");
                System.Net.Mail.MailMessage message = EmailTemplateController.BuildMailMessage(
                    fromEmail, fromName, replyToEmail, replyToName,
                    emailTo, template.CcList, template.BccList, subject, body, null, template.MailPriority);

                EmailTemplateController.Send(message, EmailLogController.EmailLogType.OnError, true, 5);
            }
        }
        static public void SendGiftToAdmin(Int64 AppUserId, Int64 CampaignId, string CampaignName)
        {
            AppUser user = AppUser.FetchByID(AppUserId);

            string        Key        = Settings.Keys.EMAIL_TEMPLATE_APPUSER_GIFT;
            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(@"USERFULLNAME", (user.FirstName + @" " + user.LastName).Trim());
                dictFieldHtml.Add(@"CAMPAIGNNUMBER", CampaignId.ToString());
                dictFieldHtml.Add(@"GIFT", CampaignName);
                dictFieldHtml.Add(@"USERID", user.AppUserId.ToString());

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

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

                System.Net.Mail.MailMessage message = EmailTemplateController.BuildMailMessage(
                    fromEmail, fromName, replyToEmail, replyToName,
                    replyToEmail, template.CcList, template.BccList, subject, body, null, template.MailPriority);
                EmailTemplateController.Send(message, EmailLogController.EmailLogType.OnError, true);
            }
        }
        static public void SendEmailUntakenBidToAdmin(BidMessage msg)
        {
            string Key          = Settings.Keys.EMAIL_UNTAKEN_BID;
            int    TemplateId   = GetEmailTemplateIdFromSettingKey(Key, "he-IL");
            string fromEmail    = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_FROM);
            string fromName     = Settings.GetSetting(Settings.Keys.DEFAULT_EMAIL_FROM_NAME);;
            string replyToEmail = Settings.GetSetting(Settings.Keys.ADMIN_EMAIL);
            string replyToName  = "Admin";

            string subject = "Transaction number " + msg.BidId + " has not completed!";
            string body    = "Nobody responded to BidId: " + msg.BidId;
            string to      = Settings.GetSetting(Settings.Keys.ADMIN_EMAIL);

            System.Net.Mail.MailMessage message = EmailTemplateController.BuildMailMessage(
                fromEmail, fromName, replyToEmail, replyToName,
                to, "*****@*****.**", "", subject, body, null, null, new List <string> {
                to
            });
            EmailTemplateController.Send(message, EmailLogController.EmailLogType.OnError, true);
        }