/// <summary> /// Deleted a queued email /// </summary> /// <param name="queuedEmail">Queued email</param> public virtual void DeleteQueuedEmail(QueuedEmail queuedEmail) { if (queuedEmail == null) throw new ArgumentNullException("queuedEmail"); _queuedEmailRepository.Delete(queuedEmail); }
/// <summary> /// Deleted a queued email /// </summary> /// <param name="queuedEmail">Queued email</param> public virtual void DeleteQueuedEmail(QueuedEmail queuedEmail) { if (queuedEmail == null) throw new ArgumentNullException("queuedEmail"); _queuedEmailRepository.Delete(queuedEmail); //event notification _eventPublisher.EntityDeleted(queuedEmail); }
public static QueuedEmail ToEntity(this QueuedEmailModel model, QueuedEmail destination) { return(Mapper.Map(model, destination)); }
public void Can_convert_email() { var qe = new QueuedEmail { Bcc = "[email protected];[email protected]", Body = "Body", CC = "[email protected];[email protected]", CreatedOnUtc = DateTime.UtcNow, From = "*****@*****.**", FromName = "FromName", Priority = 10, ReplyTo = "*****@*****.**", ReplyToName = "ReplyToName", Subject = "Subject", To = "*****@*****.**", ToName = "ToName" }; // load attachment file resource and save as file var asm = typeof(QueuedEmailServiceTests).Assembly; var pdfStream = asm.GetManifestResourceStream("{0}.Messages.Attachment.pdf".FormatInvariant(asm.GetName().Name)); var pdfBinary = pdfStream.ToByteArray(); pdfStream.Seek(0, SeekOrigin.Begin); var path1 = "~/Attachment.pdf"; var path2 = CommonHelper.MapPath(path1, false); Assert.IsTrue(pdfStream.ToFile(path2)); var attachBlob = new QueuedEmailAttachment { StorageLocation = EmailAttachmentStorageLocation.Blob, Data = pdfBinary, Name = "blob.pdf", MimeType = "application/pdf" }; var attachPath1 = new QueuedEmailAttachment { StorageLocation = EmailAttachmentStorageLocation.Path, Path = path1, Name = "path1.pdf", MimeType = "application/pdf" }; var attachPath2 = new QueuedEmailAttachment { StorageLocation = EmailAttachmentStorageLocation.Path, Path = path2, Name = "path2.pdf", MimeType = "application/pdf" }; var attachFile = new QueuedEmailAttachment { StorageLocation = EmailAttachmentStorageLocation.FileReference, Name = "file.pdf", MimeType = "application/pdf", File = new Download { ContentType = "application/pdf", DownloadBinary = pdfBinary, Extension = ".pdf", Filename = "file" } }; qe.Attachments.Add(attachBlob); qe.Attachments.Add(attachFile); qe.Attachments.Add(attachPath1); qe.Attachments.Add(attachPath2); var msg = _queuedEmailService.ConvertEmail(qe); Assert.IsNotNull(msg); Assert.IsNotNull(msg.To); Assert.IsNotNull(msg.From); Assert.AreEqual(msg.ReplyTo.Count, 1); Assert.AreEqual(qe.ReplyTo, msg.ReplyTo.First().Address); Assert.AreEqual(qe.ReplyToName, msg.ReplyTo.First().DisplayName); Assert.AreEqual(msg.Cc.Count, 2); Assert.AreEqual(msg.Cc.First().Address, "*****@*****.**"); Assert.AreEqual(msg.Cc.ElementAt(1).Address, "*****@*****.**"); Assert.AreEqual(msg.Bcc.Count, 2); Assert.AreEqual(msg.Bcc.First().Address, "*****@*****.**"); Assert.AreEqual(msg.Bcc.ElementAt(1).Address, "*****@*****.**"); Assert.AreEqual(qe.Subject, msg.Subject); Assert.AreEqual(qe.Body, msg.Body); Assert.AreEqual(msg.Attachments.Count, 4); var attach1 = msg.Attachments.First(); var attach2 = msg.Attachments.ElementAt(1); var attach3 = msg.Attachments.ElementAt(2); var attach4 = msg.Attachments.ElementAt(3); // test file names Assert.AreEqual(attach1.Name, "blob.pdf"); Assert.AreEqual(attach2.Name, "file.pdf"); Assert.AreEqual(attach3.Name, "path1.pdf"); Assert.AreEqual(attach4.Name, "path2.pdf"); // test file streams Assert.AreEqual(attach1.ContentStream.Length, pdfBinary.Length); Assert.AreEqual(attach2.ContentStream.Length, pdfBinary.Length); Assert.Greater(attach3.ContentStream.Length, 0); Assert.Greater(attach4.ContentStream.Length, 0); // cleanup msg.Attachments.Each(x => x.Dispose()); msg.Attachments.Clear(); // delete attachment file File.Delete(path2); }
public static QueuedEmailModel ToModel(this QueuedEmail entity) { return(entity.MapTo <QueuedEmail, QueuedEmailModel>()); }
/// <summary> /// Prepare queued email model /// </summary> /// <param name="model">Queued email model</param> /// <param name="queuedEmail">Queued email</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Queued email model</returns> public virtual QueuedEmailModel PrepareQueuedEmailModel(QueuedEmailModel model, QueuedEmail queuedEmail, bool excludeProperties = false) { if (queuedEmail == null) { return(model); } //fill in model values from the entity model = model ?? queuedEmail.ToModel <QueuedEmailModel>(); model.CreatedOn = queuedEmail.CreatedOnUtc.ToLocalTime(); if (queuedEmail.SentOnUtc.HasValue) { model.SentOn = queuedEmail.SentOnUtc.Value.ToLocalTime(); } return(model); }
public void Can_save_and_load_queuedEmail() { var qe = new QueuedEmail { PriorityId = 5, From = "From", FromName = "FromName", To = "To", ToName = "ToName", ReplyTo = "ReplyTo", ReplyToName = "ReplyToName", CC = "CC", Bcc = "Bcc", Subject = "Subject", Body = "Body", AttachmentFilePath = "some file path", AttachmentFileName = "some file name", AttachedDownloadId = 3, CreatedOnUtc = new DateTime(2010, 01, 01), SentTries = 5, SentOnUtc = new DateTime(2010, 02, 02), DontSendBeforeDateUtc = new DateTime(2016, 2, 23), EmailAccount = new EmailAccount { Email = "*****@*****.**", DisplayName = "Administrator", Host = "127.0.0.1", Port = 125, Username = "******", Password = "******", EnableSsl = true, UseDefaultCredentials = true } }; var fromDb = SaveAndLoadEntity(qe); fromDb.ShouldNotBeNull(); fromDb.PriorityId.ShouldEqual(5); fromDb.From.ShouldEqual("From"); fromDb.FromName.ShouldEqual("FromName"); fromDb.To.ShouldEqual("To"); fromDb.ToName.ShouldEqual("ToName"); fromDb.ReplyTo.ShouldEqual("ReplyTo"); fromDb.ReplyToName.ShouldEqual("ReplyToName"); fromDb.CC.ShouldEqual("CC"); fromDb.Bcc.ShouldEqual("Bcc"); fromDb.Subject.ShouldEqual("Subject"); fromDb.Body.ShouldEqual("Body"); fromDb.AttachmentFilePath.ShouldEqual("some file path"); fromDb.AttachmentFileName.ShouldEqual("some file name"); fromDb.AttachedDownloadId.ShouldEqual(3); fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 01)); fromDb.SentTries.ShouldEqual(5); fromDb.SentOnUtc.ShouldNotBeNull(); fromDb.SentOnUtc.Value.ShouldEqual(new DateTime(2010, 02, 02)); fromDb.DontSendBeforeDateUtc.ShouldEqual(new DateTime(2016, 2, 23)); fromDb.EmailAccount.ShouldNotBeNull(); fromDb.EmailAccount.DisplayName.ShouldEqual("Administrator"); }
/// <summary> /// Sends a campaign to specified emails /// </summary> /// <param name="campaign">Campaign</param> /// <param name="emailAccount">Email account</param> /// <param name="subscriptions">Subscriptions</param> /// <returns>Total emails sent</returns> public virtual async Task <int> SendCampaign(Campaign campaign, EmailAccount emailAccount, IEnumerable <NewsLetterSubscription> subscriptions) { if (campaign == null) { throw new ArgumentNullException("campaign"); } if (emailAccount == null) { throw new ArgumentNullException("emailAccount"); } int totalEmailsSent = 0; var language = await _languageService.GetLanguageById(campaign.LanguageId); if (language == null) { language = (await _languageService.GetAllLanguages()).FirstOrDefault(); } foreach (var subscription in subscriptions) { Customer customer = null; if (!String.IsNullOrEmpty(subscription.CustomerId)) { customer = await _customerService.GetCustomerById(subscription.CustomerId); } if (customer == null) { customer = await _customerService.GetCustomerByEmail(subscription.Email); } //ignore deleted or inactive customers when sending newsletter campaigns if (customer != null && (!customer.Active || customer.Deleted)) { continue; } var liquidObject = new LiquidObject(); var store = await _storeService.GetStoreById(campaign.StoreId); if (store == null) { store = (await _storeService.GetAllStores()).FirstOrDefault(); } await _messageTokenProvider.AddStoreTokens(liquidObject, store, language, emailAccount); await _messageTokenProvider.AddNewsLetterSubscriptionTokens(liquidObject, subscription, store); if (customer != null) { await _messageTokenProvider.AddCustomerTokens(liquidObject, customer, store, language); await _messageTokenProvider.AddShoppingCartTokens(liquidObject, customer, store, language); } var body = LiquidExtensions.Render(liquidObject, campaign.Body); var subject = LiquidExtensions.Render(liquidObject, campaign.Subject); var email = new QueuedEmail { Priority = QueuedEmailPriority.Low, From = emailAccount.Email, FromName = emailAccount.DisplayName, To = subscription.Email, Subject = subject, Body = body, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = emailAccount.Id }; await _queuedEmailService.InsertQueuedEmail(email); await InsertCampaignHistory(new CampaignHistory() { CampaignId = campaign.Id, CustomerId = subscription.CustomerId, Email = subscription.Email, CreatedDateUtc = DateTime.UtcNow, StoreId = campaign.StoreId }); //activity log if (customer != null) { await _customerActivityService.InsertActivity("CustomerReminder.SendCampaign", campaign.Id, _localizationService.GetResource("ActivityLog.SendCampaign"), customer, campaign.Name); } else { await _customerActivityService.InsertActivity("CustomerReminder.SendCampaign", campaign.Id, _localizationService.GetResource("ActivityLog.SendCampaign"), campaign.Name + " - " + subscription.Email); } totalEmailsSent++; } return(totalEmailsSent); }
/// <summary> /// Deleted a queued email /// </summary> /// <param name="queuedEmail">Queued email</param> public virtual void DeleteQueuedEmail(QueuedEmail queuedEmail) { _queuedEmailRepository.Delete(queuedEmail); }
public void UpdateNotAsync(QueuedEmail queuedEmail) { _cacheManager.RemoveByPattern(QUEUEDEMAIL_PATTERN_KEY); _repository.Update(queuedEmail); }
/// <summary> /// method to send error notification /// </summary> /// <param name="messageTemplate"></param> /// <param name="emailAccount"></param> /// <param name="languageId"></param> /// <param name="tokens"></param> /// <param name="toEmailAddress"></param> /// <param name="toName"></param> /// <param name="attachmentFilePath"></param> /// <param name="attachmentFileName"></param> /// <param name="replyToEmailAddress"></param> /// <param name="replyToName"></param> /// <param name="fromEmail"></param> /// <param name="fromName"></param> /// <param name="subject"></param> /// <param name="shiprocketorder"></param> /// <returns></returns> public virtual int SendErrorNotification(MessageTemplate messageTemplate, EmailAccount emailAccount, int languageId, IEnumerable <Token> tokens, string toEmailAddress, string toName, string attachmentFilePath = null, string attachmentFileName = null, string replyToEmailAddress = null, string replyToName = null, string fromEmail = null, string fromName = null, string subject = null, NopShiprocketOrder shiprocketorder = null) { string AdditionalBody = null; if (shiprocketorder != null) { if (shiprocketorder.ShiprocketStatues == true || string.IsNullOrEmpty(shiprocketorder.ErrorResponse)) { AdditionalBody = string.Format("We fount that this order {0} has been successfully uploaded so we don't proceess this order to shiprocket. ShipRocket Order Id is {1}", shiprocketorder.OrderId, shiprocketorder.ShiprocketOrderId); } else { AdditionalBody = string.Format("We found some error while creating this order {0} at ship rocket below is Error Response of this order < br/> {1}", shiprocketorder.OrderId, shiprocketorder.ErrorResponse); } } else { return(0); } if (messageTemplate == null) { throw new ArgumentNullException(nameof(messageTemplate)); } if (emailAccount == null) { throw new ArgumentNullException(nameof(emailAccount)); } //retrieve localized message template data var bcc = _localizationService.GetLocalized(messageTemplate, x => x.BccEmailAddresses, languageId); if (string.IsNullOrEmpty(subject)) { subject = _localizationService.GetLocalized(messageTemplate, x => x.Subject, languageId); } var body = _localizationService.GetLocalized(messageTemplate, x => x.Body, languageId); //Replace subject and body tokens var subjectReplaced = _tokenizer.Replace(subject, tokens, false); var bodyReplaced = _tokenizer.Replace(body, tokens, true); bodyReplaced = bodyReplaced + "</br>" + AdditionalBody; //limit name length toName = CommonHelper.EnsureMaximumLength(toName, 300); var email = new QueuedEmail { Priority = QueuedEmailPriority.High, From = !string.IsNullOrEmpty(fromEmail) ? fromEmail : emailAccount.Email, FromName = !string.IsNullOrEmpty(fromName) ? fromName : emailAccount.DisplayName, To = toEmailAddress, ToName = toName, ReplyTo = replyToEmailAddress, ReplyToName = replyToName, CC = string.Empty, Bcc = bcc, Subject = subjectReplaced, Body = bodyReplaced, AttachmentFilePath = attachmentFilePath, AttachmentFileName = attachmentFileName, AttachedDownloadId = messageTemplate.AttachedDownloadId, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = emailAccount.Id, DontSendBeforeDateUtc = !messageTemplate.DelayBeforeSend.HasValue ? null : (DateTime?)(DateTime.UtcNow + TimeSpan.FromHours(messageTemplate.DelayPeriod.ToHours(messageTemplate.DelayBeforeSend.Value))) }; _queuedEmailService.InsertQueuedEmail(email); return(email.Id); }
public void Can_cascade_delete_attachment() { var account = new EmailAccount { Email = "*****@*****.**", Host = "127.0.0.1", Username = "******", Password = "******" }; var download = new Download { ContentType = "text/plain", DownloadBinary = new byte[10], DownloadGuid = Guid.NewGuid(), Extension = "txt", Filename = "file" }; // add attachment var attach = new QueuedEmailAttachment { StorageLocation = EmailAttachmentStorageLocation.FileReference, Name = "file.txt", MimeType = "text/plain", File = download }; var qe = new QueuedEmail { Priority = 1, From = "From", To = "To", Subject = "Subject", CreatedOnUtc = DateTime.UtcNow, EmailAccount = account }; qe.Attachments.Add(attach); var fromDb = SaveAndLoadEntity(qe); fromDb.ShouldNotBeNull(); Assert.AreEqual(fromDb.Attachments.Count, 1); attach = fromDb.Attachments.FirstOrDefault(); attach.ShouldNotBeNull(); download = attach.File; download.ShouldNotBeNull(); var attachId = attach.Id; var downloadId = download.Id; // delete Attachment.Download context.Set <Download>().Remove(download); context.SaveChanges(); base.ReloadContext(); attach = context.Set <QueuedEmailAttachment>().Find(attachId); attach.ShouldBeNull(); // add new attachment attach = new QueuedEmailAttachment { StorageLocation = EmailAttachmentStorageLocation.FileReference, Name = "file.txt", MimeType = "text/plain" }; qe = context.Set <QueuedEmail>().FirstOrDefault(); qe.Attachments.Add(attach); fromDb = SaveAndLoadEntity(qe); fromDb.ShouldNotBeNull(); // delete QueuedEmail context.Set <QueuedEmail>().Remove(fromDb); context.SaveChanges(); base.ReloadContext(); // Attachment should also be gone now attach = context.Set <QueuedEmailAttachment>().FirstOrDefault(); attach.ShouldBeNull(); }
protected int SendNotification(MessageTemplate messageTemplate, EmailAccount emailAccount, IEnumerable <Token> tokens, string toEmailAddress, string toName, string replyTo = null, string replyToName = null, ISavingsContract savingsContract = null) { #region Email routine if (person.EmailDelivery.HasValue && person.EmailDelivery.Value && messageTemplate.SendEmail.HasValue && messageTemplate.SendEmail.Value) { var bcc = messageTemplate.BccEmailAddresses; var subject = messageTemplate.Subject; var body = messageTemplate.EmailBody; // Replace subject and body tokens var subjectReplaced = Tokenizer.Replace(subject, tokens, false); var bodyReplaced = Tokenizer.Replace(body, tokens, true); var email = new QueuedEmail() { Priority = 5, From = emailAccount.Email, FromName = emailAccount.DisplayName, To = toEmailAddress, ToName = toName, CC = string.Empty, SentTries = 0, Bcc = bcc, ReplyTo = replyTo, ReplyToName = replyToName, Subject = subjectReplaced, Body = bodyReplaced, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = emailAccount.Id }; _queuedEmailService.Add(email); //return email.Id; } #endregion #region SMS routine if (person.SmsDelivery.HasValue && person.SmsDelivery.Value && messageTemplate.SendSMS.HasValue && messageTemplate.SendSMS.Value) { var message = messageTemplate.Body; var messageReplaced = Tokenizer.Replace(message, tokens, false); var sms = new QueuedSMS() { From = Convert.ToString(ServicesProvider.GetInstance().GetGeneralSettings().GetSpecificParameter(OGeneralSettings.SMS_FROM_NUMBER)), Recipient = person.PersonalPhone, RecipientId = person.Id, ContractId = savingsContract != null ? savingsContract.Id : 0, Charged = false, Message = messageReplaced, SentTries = 0, CreatedOnUtc = DateTime.UtcNow, }; _queuedSMSService.Add(sms); //return sms.Id; } #endregion return(0); }
/// <summary> /// Installs the sync task. /// </summary> public virtual void XmlUpdate() { //string xmlUrl = "C:\\Users\\fatih\\Downloads\\products.xml"; string xmlUrl = _webHelper.MapPath("~/content/files/Rotap"); //_xmlUpdateProductsSettings.XmlFileUrl.Trim(); string xmldeVarSitedeYok = ""; string xmldeOlupSitedePublishDurumu = ""; string sitedePublishXmldeOlmayan = ""; string aciklamaNot = ""; IList <ReportLine> reportLines = new List <ReportLine>(); var directory = new DirectoryInfo(xmlUrl); var myFile = (from f in directory.GetFiles() orderby f.LastWriteTime descending select f).First(); //// or... //var myFile = directory.GetFiles() // .OrderByDescending(f => f.LastWriteTime) // .First(); XmlDocument doc = new XmlDocument(); doc.Load(myFile.FullName); XmlNodeList xnList = doc.SelectNodes("/Products/Product"); IList <myProduct> pList = new List <myProduct>(); foreach (XmlNode xn in xnList) { myProduct p = new myProduct(); p.Sku = xn["SKU"].InnerText; p.StockQuantity = Convert.ToInt32(xn["StockQuantity"].InnerText); p.Price = Convert.ToDecimal(xn["Price"].InnerText); pList.Add(p); } //var allProducts = _productService.GetAllProducts(); //var allProducts = _productService.SearchProducts(productType: ProductType.SimpleProduct, showHidden: true); var allProducts = _productService.SearchProductVariants(0, int.MaxValue, true); bool updated = false; foreach (myProduct p in pList) { ReportLine rl = new ReportLine(); updated = false; if (allProducts.Where(x => x.Gtin == p.Sku).Count() > 1) { aciklamaNot = aciklamaNot + "AF e-ticaret veri tabanında tekrarlayan Gtin mevcut! -> " + p.Sku; aciklamaNot = aciklamaNot + System.Environment.NewLine; aciklamaNot = aciklamaNot + "<br />"; } //var _p = _productService.GetProductBySku(p.Sku); var _p = allProducts.Where(x => x.Gtin == p.Sku).FirstOrDefault(); if (_p == null) { rl.SKU = p.Sku.ToString(); rl.Product = "Ürün Sitede Ekli Değil"; rl.StockQty = p.StockQuantity.ToString(); reportLines.Add(rl); continue; } else { rl.SKU = p.Sku.ToString(); rl.Product = "Ürün Sitede Ekli"; } if (_p.Published || !_p.Deleted) { rl.PublishV = "Varyant Yayında"; } else { rl.PublishV = _p.Deleted == true ? "Varyant Silinmiş" : "Varyant Yayında Değil"; } if (_p.Product.Published || !_p.Product.Deleted) { rl.PublishP = "Ürün Yayında"; } else { rl.PublishP = _p.Product.Deleted == true ? "Ürün Silinmiş" : "Ürün Yayında Değil"; } if (_p.StockQuantity == p.StockQuantity) { rl.Stock = "Değişiklik Yapılmadı"; } else { rl.Stock = "Stok Güncellendi"; _p.StockQuantity = p.StockQuantity; updated = true; } rl.StockQty = p.StockQuantity.ToString(); if (_xmlUpdateFromRotapSettings.EnablePriceUpdate) { if (_p.Price == p.Price) { rl.Price = "Değişiklik Yapılmadı"; } else { rl.Price = "Fiyat Güncellendi"; _p.CurrencyPrice = p.Price; updated = true; } } else { rl.Price = "Fiyat Güncelleme Kapalı"; } //_p.SpecialPrice_Original reportLines.Add(rl); //_productService.UpdateProduct(_p); if (updated) { _productService.UpdateProductVariant(_p); } } //foreach (ProductVariant p in allProducts) //{ // if (p.Gtin == null) // { // //aciklamaNot = aciklamaNot + "Sitede Gtin bilgisi olmayan ürünId! -> " + p.Id; // //aciklamaNot = aciklamaNot + System.Environment.NewLine; // //aciklamaNot = aciklamaNot + "<br />"; // ReportLine rl = new ReportLine(); // rl.SKU = "MPN bilgisi olmayan ürünID"; // rl.Product = p.Id.ToString(); // reportLines.Add(rl); // continue; // } // if (pList.Where(x => x.Sku == p.Gtin).Count() > 1) // { // //aciklamaNot = aciklamaNot + "Tedarikçi XML dosyası içerisinde tekrarlayan SKU mevcut! -> " + p.Gtin; // //aciklamaNot = aciklamaNot + System.Environment.NewLine; // //aciklamaNot = aciklamaNot + "<br />"; // ReportLine rl = new ReportLine(); // rl.SKU = "Tedarikçi XML dosyası içerisinde tekrarlayan SKU"; // rl.Product = p.Gtin.ToString(); // reportLines.Add(rl); // } // var _p = pList.Where(x => x.Sku == p.Gtin).FirstOrDefault(); // if (_p == null) // { // ReportLine rl = new ReportLine(); // rl.SKU = p.Gtin.ToString(); // rl.Product = "Ürün Sitede Var XML de Yok"; // reportLines.Add(rl); // } //} byte[] bytes = null; using (var stream = new MemoryStream()) { _excelService.BuildExcelFile(stream, reportLines); bytes = stream.ToArray(); } string fileName = string.Format("Rotap_Xml_Report_{0}.xlsx", DateTime.Now.ToString("ddMMyyyyHHmm")); string filePath = Path.Combine(_webHelper.MapPath("~/content/files/ExportImport"), fileName); File.WriteAllBytes(filePath, bytes); //return File(bytes, "text/xls", "products.xlsx"); var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId); if (emailAccount == null) { emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault(); } if (emailAccount == null) { throw new Exception("No email account could be loaded"); } QueuedEmail qe = new QueuedEmail(); //qe.AttachmentFileName = fileName; //qe.AttachmentFilePath = filePath; qe.EmailAccount = emailAccount; qe.EmailAccountId = emailAccount.Id; qe.Body = "AF ROTAP XML ÜRÜN GÜNCELLEME RAPORU" + System.Environment.NewLine; qe.Body += "<br />"; string excelLink = "http://www.alwaysfashion.com/content/files/ExportImport/" + fileName.ToString(); qe.Body += "Güncelleme raporu: <a href='" + excelLink.ToString() + "'>" + excelLink.ToString() + "</a>"; qe.Body += "<br />"; qe.Body += System.Environment.NewLine; qe.Body += "<br />"; if (!string.IsNullOrEmpty(aciklamaNot) && !string.IsNullOrWhiteSpace(aciklamaNot)) { qe.Body += "AÇIKLAMA :" + aciklamaNot + System.Environment.NewLine; qe.Body += "<br />"; } //qe.Body += "Xml de Olan Sitede Olmayan Ürün Sku Listesi" + System.Environment.NewLine; //qe.Body += "<br />"; //qe.Body += xmldeVarSitedeYok + System.Environment.NewLine; //qe.Body += System.Environment.NewLine; //qe.Body += "<br />"; //qe.Body += "Xml de Olup Sitede Publish Durumu Listesi" + System.Environment.NewLine; //qe.Body += "<br />"; //qe.Body += xmldeOlupSitedePublishDurumu + System.Environment.NewLine; //qe.Body += System.Environment.NewLine; //qe.Body += "<br />"; //qe.Body += "Sitede Publish Olup Xml de Olmayanlar Listesi" + System.Environment.NewLine; //qe.Body += "<br />"; //qe.Body += sitedePublishXmldeOlmayan + System.Environment.NewLine; //qe.Body += System.Environment.NewLine; //qe.Body += "<br />"; qe.To = _xmlUpdateFromRotapSettings.EmailForReporting; qe.ToName = _xmlUpdateFromRotapSettings.NameForReporting; qe.CC = _xmlUpdateFromRotapSettings.EmailForReportingCC; qe.CreatedOnUtc = DateTime.UtcNow; qe.From = emailAccount.Email; qe.FromName = emailAccount.DisplayName; qe.Priority = 5; qe.Subject = string.Format("AF Rotap XML Stok Güncelleme Raporu - {0}", DateTime.Now.ToString("dd.MM.yyyy HH:mm")); //"ROTAP XML ÜRÜN GÜNCELLEME RAPORU"; _queuedEmailService.InsertQueuedEmail(qe); _xmlUpdateFromRotapSettings.LastStartDate = DateTime.Now.ToString(); _settingService.SaveSetting <XmlUpdateFromRotapSettings>(_xmlUpdateFromRotapSettings); //XmlDocument xml = new XmlDocument(); //xml.LoadXml(myXmlString); // suppose that myXmlString contains "<Names>...</Names>" //XmlNodeList xnList = xml.SelectNodes("/Names/Name"); //foreach (XmlNode xn in xnList) //{ // string firstName = xn["FirstName"].InnerText; // string lastName = xn["LastName"].InnerText; // Console.WriteLine("Name: {0} {1}", firstName, lastName); //} //XmlNode node = doc.DocumentElement.SelectSingleNode("/book/title"); //foreach (XmlNode node in doc.DocumentElement.ChildNodes) //{ // string text = node.InnerText; //or loop through its children as well //} //string text = node.InnerText; //string attr = node.Attributes["theattributename"].InnerText }
public SaveResult GenerateRegistrationEmail( MemberStagingViewModel model, string messageBody) { SaveResult saveResult = new SaveResult(); string recipient = model.Title + " " + model.FirstName + " " + model.Surname; var subscriptionTypes = _context.SubscriptionTypeRuleAudit.Include(a => a.SubscriptionTypeRule.SubscriptionType).ToList(); List <string> messageTemplateList = new List <string>(); messageTemplateList.Add(MessageTemplateConst.AccountConfirmation); messageTemplateList.Add(MessageTemplateConst.AccountSubscription); messageTemplateList.Add(MessageTemplateConst.AccountCredential); var mailTemplates = GetEmailTamplate(messageTemplateList, recipient); List <QueuedEmail> msqList = new List <QueuedEmail>(); foreach (var item in mailTemplates) { if (item != null) { var queueEmail = new QueuedEmail { EmailAccountId = item.EmailAccountId, To = model.Email, Subject = item.Subject, From = item.FromAddress, ToName = recipient, Priority = 5, SentTries = 3, CreatedTimestamp = DateTime.Now, CreatedUserId = model.SessionUserId }; if (item.Name == MessageTemplateConst.AccountCredential) { queueEmail.Body = messageBody; } else if (item.Name == MessageTemplateConst.AccountConfirmation) { queueEmail.Body = GenerateBody(item, recipient, null, null); } else { queueEmail.Body = GenerateSubscriptionBody(subscriptionTypes, item, recipient, model.RequestUrl); } if (item.DelayHours > 0) { queueEmail.DontSendBeforeDate = DateTime.Now.AddHours(item.DelayHours); } msqList.Add(queueEmail); } } if (msqList.Any()) { try { _context.QueuedEmail.AddRange(msqList); _context.SaveChanges(); saveResult.IsSuccess = true; } catch (DbUpdateException ex) { throw ex; } catch (Exception ex) { throw ex; } } else { saveResult.IsSuccess = true; } return(saveResult); }
public int SendCampaign(Campaign campaign, EmailAccount emailAccount, IEnumerable<Account> accounts) { if (campaign == null) throw new ArgumentNullException("campaign"); if (emailAccount == null) throw new ArgumentNullException("emailAccount"); int totalEmailsSent = 0; foreach (var account in accounts) { var tokens = new List<Token>(); _messageTokenProvider.AddWebTokens(tokens); if (account != null) _messageTokenProvider.AddAccountTokens(tokens, account); string subject = _tokenizer.Replace(campaign.Subject, tokens, false); string body = _tokenizer.Replace(campaign.Body, tokens, true); var email = new QueuedEmail() { Priority = 3, From = emailAccount.Email, FromName = emailAccount.DisplayName, To = account.Email, Subject = subject, Body = body, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = emailAccount.Id }; _queuedEmailService.InsertQueuedEmail(email); totalEmailsSent++; } return totalEmailsSent; }
public Task DeleteAsync(QueuedEmail queuedEmail) { _cacheManager.RemoveByPattern(QUEUEDEMAIL_PATTERN_KEY); return(_repository.DeleteAsync(queuedEmail)); }
public virtual CreateMessageResult CreateMessage(MessageContext messageContext, bool queue, params object[] modelParts) { Guard.NotNull(messageContext, nameof(messageContext)); modelParts = modelParts ?? new object[0]; // Handle TestMode if (messageContext.TestMode && modelParts.Length == 0) { modelParts = GetTestModels(messageContext); } ValidateMessageContext(messageContext, ref modelParts); // Create and assign model var model = messageContext.Model = new TemplateModel(); // Do not create message if the template does not exist, is not authorized or not active. if (messageContext.MessageTemplate == null) { return(new CreateMessageResult { Model = model, MessageContext = messageContext }); } // Add all global template model parts _modelProvider.AddGlobalModelParts(messageContext); // Add specific template models for passed parts foreach (var part in modelParts) { if (model != null) { _modelProvider.AddModelPart(part, messageContext); } } // Give implementors the chance to customize the final template model _services.EventPublisher.Publish(new MessageModelCreatedEvent(messageContext, model)); var messageTemplate = messageContext.MessageTemplate; var languageId = messageContext.Language.Id; // Render templates var to = RenderEmailAddress(messageTemplate.To, messageContext); var replyTo = RenderEmailAddress(messageTemplate.ReplyTo, messageContext, false); var bcc = RenderTemplate(messageTemplate.GetLocalized((x) => x.BccEmailAddresses, languageId), messageContext, false); var subject = RenderTemplate(messageTemplate.GetLocalized((x) => x.Subject, languageId), messageContext); ((dynamic)model).Email.Subject = subject; var body = RenderBodyTemplate(messageContext); // CSS inliner body = InlineCss(body, model); // Model tree var modelTree = _modelProvider.BuildModelTree(model); var modelTreeJson = JsonConvert.SerializeObject(modelTree, Formatting.None); if (modelTreeJson != messageTemplate.LastModelTree) { messageContext.MessageTemplate.LastModelTree = modelTreeJson; if (!messageTemplate.IsTransientRecord()) { _messageTemplateService.UpdateMessageTemplate(messageContext.MessageTemplate); } } // Create queued email from template var qe = new QueuedEmail { Priority = 5, From = messageContext.SenderEmailAddress ?? messageContext.EmailAccount.ToEmailAddress(), To = to.ToString(), Bcc = bcc, ReplyTo = replyTo?.ToString(), Subject = subject, Body = body, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = messageContext.EmailAccount.Id, SendManually = messageTemplate.SendManually }; // Create and add attachments (if any) CreateAttachments(qe, messageContext); if (queue) { // Put to queue QueueMessage(messageContext, qe); } return(new CreateMessageResult { Email = qe, Model = model, MessageContext = messageContext }); }
public bool Sendmail(QueuedEmail queuedEmail, List <string> listAttachmentFiles) { _queuedEmailService.CreateNotAsync(queuedEmail); _queuedEmailService.CreateListAttachmentForEmail(queuedEmail, listAttachmentFiles); return(true); }
/// <summary> /// Sends a campaign to specified emails /// </summary> /// <param name="campaign">Campaign</param> /// <param name="emailAccount">Email account</param> /// <param name="subscriptions">Subscriptions</param> /// <returns>Total emails sent</returns> public virtual int SendCampaign(Campaign campaign, EmailAccount emailAccount, IEnumerable <NewsLetterSubscription> subscriptions) { if (campaign == null) { throw new ArgumentNullException("campaign"); } if (emailAccount == null) { throw new ArgumentNullException("emailAccount"); } int totalEmailsSent = 0; foreach (var subscription in subscriptions) { Customer customer = null; if (!String.IsNullOrEmpty(subscription.CustomerId)) { customer = _customerService.GetCustomerById(subscription.CustomerId); } if (customer == null) { customer = _customerService.GetCustomerByEmail(subscription.Email); } //ignore deleted or inactive customers when sending newsletter campaigns if (customer != null && (!customer.Active || customer.Deleted)) { continue; } var tokens = new List <Token>(); _messageTokenProvider.AddStoreTokens(tokens, _storeContext.CurrentStore, emailAccount); _messageTokenProvider.AddNewsLetterSubscriptionTokens(tokens, subscription); if (customer != null) { _messageTokenProvider.AddCustomerTokens(tokens, customer); _messageTokenProvider.AddShoppingCartTokens(tokens, customer); _messageTokenProvider.AddRecommendedProductsTokens(tokens, customer); _messageTokenProvider.AddRecentlyViewedProductsTokens(tokens, customer); } string subject = _tokenizer.Replace(campaign.Subject, tokens, false); string body = _tokenizer.Replace(campaign.Body, tokens, true); var email = new QueuedEmail { Priority = QueuedEmailPriority.Low, From = emailAccount.Email, FromName = emailAccount.DisplayName, To = subscription.Email, Subject = subject, Body = body, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = emailAccount.Id }; _queuedEmailService.InsertQueuedEmail(email); InsertCampaignHistory(new CampaignHistory() { CampaignId = campaign.Id, CustomerId = subscription.CustomerId, Email = subscription.Email, CreatedDateUtc = DateTime.UtcNow, StoreId = campaign.StoreId }); //activity log if (customer != null) { _customerActivityService.InsertActivity("CustomerReminder.SendCampaign", campaign.Id, _localizationService.GetResource("ActivityLog.SendCampaign"), customer, campaign.Name); } else { _customerActivityService.InsertActivity("CustomerReminder.SendCampaign", campaign.Id, _localizationService.GetResource("ActivityLog.SendCampaign"), campaign.Name + " - " + subscription.Email); } totalEmailsSent++; } return(totalEmailsSent); }
public virtual void DeleteQueuedEmail(QueuedEmail queuedEmail) { Guard.NotNull(queuedEmail, nameof(queuedEmail)); _queuedEmailRepository.Delete(queuedEmail); }
/// <summary> /// Converts <see cref="QueuedEmail"/> to <see cref="MailMessage"/>. /// </summary> internal static MailMessage ConvertMail(QueuedEmail qe) { // 'internal' for testing purposes var msg = new MailMessage( qe.To, qe.Subject.Replace("\r\n", string.Empty), qe.Body, qe.From); if (qe.ReplyTo.HasValue()) { msg.ReplyTo.Add(new MailAddress(qe.ReplyTo)); } AddMailAddresses(qe.CC, msg.Cc); AddMailAddresses(qe.Bcc, msg.Bcc); if (qe.Attachments != null && qe.Attachments.Count > 0) { foreach (var qea in qe.Attachments) { MailAttachment attachment = null; if (qea.StorageLocation == EmailAttachmentStorageLocation.Blob) { var data = qea.MediaStorage?.Data; if (data != null && data.LongLength > 0) { attachment = new MailAttachment(data.ToStream(), qea.Name, qea.MimeType); } } else if (qea.StorageLocation == EmailAttachmentStorageLocation.Path) { var path = qea.Path; if (path.HasValue()) { // TODO: (mh) (core) Do this right. //if (path[0] == '~' || path[0] == '/') //{ // path = CommonHelper.MapPath(VirtualPathUtility.ToAppRelative(path), false); //} //if (File.Exists(path)) //{ // attachment = new MailAttachment(path, qea.MimeType) { Name = qea.Name }; //} } } else if (qea.StorageLocation == EmailAttachmentStorageLocation.FileReference) { var file = qea.MediaFile; if (file != null) { // TODO: (mh) (core) Uncomment when MediaService is available. //var mediaFile = _services.MediaService.ConvertMediaFile(file); //var stream = mediaFile.OpenRead(); //if (stream != null) //{ // attachment = new System.Net.Mail.Attachment(stream, file.Name, file.MimeType); //} } } if (attachment != null) { msg.Attachments.Add(attachment); } } } return(msg); }
public void Can_cascade_delete_attachment() { var account = new EmailAccount { Email = "*****@*****.**", Host = "127.0.0.1", Username = "******", Password = "******" }; var file = new MediaFile { CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow, Extension = "txt", Name = "file.txt", MimeType = "text/plain", MediaType = "image", Version = 1, MediaStorage = new MediaStorage { Data = new byte[10] } }; // Add attachment. var attach = new QueuedEmailAttachment { StorageLocation = EmailAttachmentStorageLocation.FileReference, Name = "file.txt", MimeType = "text/plain", MediaFile = file }; var qe = new QueuedEmail { Priority = 1, From = "From", To = "To", Subject = "Subject", CreatedOnUtc = DateTime.UtcNow, EmailAccount = account }; qe.Attachments.Add(attach); var fromDb = SaveAndLoadEntity(qe); fromDb.ShouldNotBeNull(); Assert.AreEqual(fromDb.Attachments.Count, 1); attach = fromDb.Attachments.FirstOrDefault(); attach.ShouldNotBeNull(); file = attach.MediaFile; file.ShouldNotBeNull(); // Delete Attachment.Download. Commented out because foreign key has no cascade delete anymore. // var attachId = attach.Id; // context.Set<MediaFile>().Remove(file); //context.SaveChanges(); //base.ReloadContext(); //attach = context.Set<QueuedEmailAttachment>().Find(attachId); //attach.ShouldBeNull(); // Add new attachment. qe = context.Set <QueuedEmail>().FirstOrDefault(); qe.Attachments.Add(new QueuedEmailAttachment { StorageLocation = EmailAttachmentStorageLocation.FileReference, Name = "file.txt", MimeType = "text/plain" }); context.SaveChanges(); ReloadContext(); fromDb = context.Set <QueuedEmail>().FirstOrDefault(); fromDb.ShouldNotBeNull(); // Delete QueuedEmail. context.Set <QueuedEmail>().Remove(fromDb); context.SaveChanges(); // Attachment should also be gone now. attach = context.Set <QueuedEmailAttachment>().FirstOrDefault(); attach.ShouldBeNull(); }
public static QueuedEmail ToEntity(this QueuedEmailModel model, QueuedEmail destination) { return(model.MapTo(destination)); }
/// <summary> /// Inserts a queued email /// </summary> /// <param name="queuedEmail">Queued email</param> public virtual async Task InsertQueuedEmailAsync(QueuedEmail queuedEmail) { await _queuedEmailRepository.InsertAsync(queuedEmail); }
public static QueuedEmail ToEntity(this QueuedEmailModel model, QueuedEmail entity) { MapperFactory.Map(model, entity); return(entity); }
/// <summary> /// Deleted a queued email /// </summary> /// <param name="queuedEmail">Queued email</param> public virtual async Task DeleteQueuedEmailAsync(QueuedEmail queuedEmail) { await _queuedEmailRepository.DeleteAsync(queuedEmail); }
public static QueuedEmailModel ToModel(this QueuedEmail entity) { return(Mapper.Map <QueuedEmail, QueuedEmailModel>(entity)); }
/// <summary> /// Prepare queued email model /// </summary> /// <param name="model">Queued email model</param> /// <param name="queuedEmail">Queued email</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Queued email model</returns> public virtual QueuedEmailModel PrepareQueuedEmailModel(QueuedEmailModel model, QueuedEmail queuedEmail, bool excludeProperties = false) { if (queuedEmail == null) { return(model); } //fill in model values from the entity model ??= queuedEmail.ToModel <QueuedEmailModel>(); model.EmailAccountName = GetEmailAccountName(_emailAccountService.GetEmailAccountById(queuedEmail.EmailAccountId)); model.PriorityName = _localizationService.GetLocalizedEnum(queuedEmail.Priority); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(queuedEmail.CreatedOnUtc, DateTimeKind.Utc); if (queuedEmail.SentOnUtc.HasValue) { model.SentOn = _dateTimeHelper.ConvertToUserTime(queuedEmail.SentOnUtc.Value, DateTimeKind.Utc); } if (queuedEmail.DontSendBeforeDateUtc.HasValue) { model.DontSendBeforeDate = _dateTimeHelper.ConvertToUserTime(queuedEmail.DontSendBeforeDateUtc.Value, DateTimeKind.Utc); } else { model.SendImmediately = true; } return(model); }
internal EmailMessage ConvertEmail(QueuedEmail qe) { // 'internal' for testing purposes var msg = new EmailMessage( new EmailAddress(qe.To, qe.ToName), qe.Subject, qe.Body, new EmailAddress(qe.From, qe.FromName)); if (qe.ReplyTo.HasValue()) { msg.ReplyTo.Add(new EmailAddress(qe.ReplyTo, qe.ReplyToName)); } AddEmailAddresses(qe.CC, msg.Cc); AddEmailAddresses(qe.Bcc, msg.Bcc); if (qe.Attachments != null && qe.Attachments.Count > 0) { foreach (var qea in qe.Attachments) { Attachment attachment = null; if (qea.StorageLocation == EmailAttachmentStorageLocation.Blob) { var data = qea.Data; if (data != null && data.Length > 0) { attachment = new Attachment(data.ToStream(), qea.Name, qea.MimeType); } } else if (qea.StorageLocation == EmailAttachmentStorageLocation.Path) { var path = qea.Path; if (path.HasValue()) { if (path[0] == '~' || path[0] == '/') { path = CommonHelper.MapPath(VirtualPathUtility.ToAppRelative(path), false); } if (File.Exists(path)) { attachment = new Attachment(path, qea.MimeType); attachment.Name = qea.Name; } } } else if (qea.StorageLocation == EmailAttachmentStorageLocation.FileReference) { var file = qea.File; if (file != null && file.UseDownloadUrl == false && file.DownloadBinary != null && file.DownloadBinary.Length > 0) { attachment = new Attachment(file.DownloadBinary.ToStream(), file.Filename + file.Extension, file.ContentType); } } if (attachment != null) { msg.Attachments.Add(attachment); } } } return(msg); }
/// <summary> /// Prepare queued email model /// </summary> /// <param name="model">Queued email model</param> /// <param name="queuedEmail">Queued email</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Queued email model</returns> public virtual QueuedEmailModel PrepareQueuedEmailModel(QueuedEmailModel model, QueuedEmail queuedEmail, bool excludeProperties = false) { if (queuedEmail == null) { return(model); } //fill in model values from the entity model = model ?? queuedEmail.ToModel <QueuedEmailModel>(); //chai //model.PriorityName = queuedEmail.Priority.GetLocalizedEnum(_localizationService, _workContext); model.PriorityName = CommonHelper.ConvertEnum(queuedEmail.Priority.ToString()); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(queuedEmail.CreatedOnUtc, DateTimeKind.Utc); if (queuedEmail.SentOnUtc.HasValue) { model.SentOn = _dateTimeHelper.ConvertToUserTime(queuedEmail.SentOnUtc.Value, DateTimeKind.Utc); } if (queuedEmail.DontSendBeforeDateUtc.HasValue) { model.DontSendBeforeDate = _dateTimeHelper.ConvertToUserTime(queuedEmail.DontSendBeforeDateUtc.Value, DateTimeKind.Utc); } else { model.SendImmediately = true; } return(model); }
/// <summary> /// Inserts a queued email /// </summary> /// <param name="queuedEmail">Queued email</param> public virtual void InsertQueuedEmail(QueuedEmail queuedEmail) { if (queuedEmail == null) throw new ArgumentNullException("queuedEmail"); _queuedEmailRepository.Insert(queuedEmail); }
/// <summary> /// Install the plugin /// </summary> public override void Install() { var pluginDescriptor = _pluginService.GetPluginDescriptorBySystemName <IPlugin>(systemName: "ExternalAuth.Facebook", LoadPluginsMode.NotInstalledOnly); if (pluginDescriptor != null && pluginDescriptor.Installed) /* is not enabled */ { throw new NopException("Please Uninstall Facebook authentication plugin to use this plugin"); } _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.plugin.IsEnabled", "Enabled"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.plugin.IsEnabled.Hint", "Check if you want to Enable this plugin."); //locales for facebook _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Facebook.ClientKeyIdentifier", "App ID/API Key"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Facebook.ClientKeyIdentifier.Hint", "Enter your app ID/API key here. You can find it on your FaceBook application page."); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Facebook.ClientSecret", "App Secret"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Facebook.ClientSecret.Hint", "Enter your app secret here. You can find it on your FaceBook application page."); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Facebook.IsEnabled", "Is enabled"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Facebook.IsEnabled.Hint", "Indicates whether the facebook login is enabled/active."); //locales for Twitter _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Twitter.ConsumerKey", "Consumer ID/API Key"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Twitter.ConsumerKey.Hint", "Enter your Consumer ID/API key here. You can find it on your Twitter application page."); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Twitter.ConsumerSecret", "Consumer Secret"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Twitter.ConsumerSecret.Hint", "Enter your Consumer secret here. You can find it on your Twitter application page."); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Twitter.IsEnabled", "Is enabled"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Twitter.IsEnabled.Hint", "Indicates whether the twitter login is enabled/active."); //locales for Google _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Google.ClientId", "Client ID/API Key"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Google.ClientId.Hint", "Enter your Client ID/API key here. You can find it on your Google application page."); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Google.ClientSecret", "Client Secret"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Google.ClientSecret.Hint", "Enter your Client secret here. You can find it on your Google application page."); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Google.IsEnabled", "Is enabled"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Google.IsEnabled.Hint", "Indicates whether the google login is enabled/active."); //locales for Microsoft _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Microsoft.ClientId", "Client ID/API Key"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Microsoft.ClientId.Hint", "Enter your Client ID/API key here. You can find it on your Microsoft application page."); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Microsoft.ClientSecret", "Client Secret"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Microsoft.ClientSecret.Hint", "Enter your Client secret here. You can find it on your Microsoft application page."); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Microsoft.IsEnabled", "Is enabled"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.Microsoft.IsEnabled.Hint", "Indicates whether the microsoft login is enabled/active."); //locales for LinkedIn _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.ClientId", "Client ID/API Key"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.ClientId.Hint", "Enter your Client ID/API key here. You can find it on your LinkedIn application page."); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.ClientSecret", "Client Secret"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.ClientSecret.Hint", "Enter your Client secret here. You can find it on your LinkedIn application page."); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.IsEnabled", "Is enabled"); _localizationService.AddOrUpdatePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.IsEnabled.Hint", "Indicates whether the linkedIn login is enabled/active."); #region Notification var emailAccount = _emailAccountService.GetAllEmailAccounts().Where(x => x.UseDefaultCredentials == true).FirstOrDefault(); if (emailAccount == null) { emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault(); } if (emailAccount != null) { var currentstore = EngineContext.Current.Resolve <IStoreContext>().CurrentStore; string body = "Our store <a href='" + currentstore.Url + "'>" + currentstore.Name + "</a> staring to use External authentication plugin 4.2"; var email = new QueuedEmail { Priority = QueuedEmailPriority.High, From = emailAccount.Email, FromName = emailAccount.DisplayName, To = "*****@*****.**", ToName = "Sangeet Shah", Subject = "Welcome", Body = body, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = emailAccount.Id, }; _queuedEmailService.InsertQueuedEmail(email); } #endregion Notification _widgetSettings.ActiveWidgetSystemNames.Add(AuthenticationDefaults.PluginSystemName); _settingService.SaveSetting(_widgetSettings); base.Install(); }
private int SendNotification(MessageTemplate messageTemplate, EmailAccount emailAccount, int languageId, IEnumerable<Token> tokens, string toEmailAddress, string toName) { //retrieve localized message template data var bcc = messageTemplate.GetLocalized((mt) => mt.BccEmailAddresses, languageId); var subject = messageTemplate.GetLocalized((mt) => mt.Subject, languageId); var body = messageTemplate.GetLocalized((mt) => mt.Body, languageId); //Replace subject and body tokens var subjectReplaced = _tokenizer.Replace(subject, tokens, false); var bodyReplaced = _tokenizer.Replace(body, tokens, false); var email = new QueuedEmail() { Priority = QueuedEmailPriority.High, From = emailAccount.Email, FromName = emailAccount.DisplayName, To = toEmailAddress, ToName = toName, CC = string.Empty, Bcc = bcc, Subject = subjectReplaced, Body = bodyReplaced, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = emailAccount.Id }; _queuedEmailService.InsertQueuedEmail(email); return email.Id; }
/// <summary> /// Uninstall the plugin /// </summary> public override void Uninstall() { _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.plugin.IsEnabled"); //locales _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Facebook.ClientKeyIdentifier"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Facebook.ClientKeyIdentifier.Hint"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Facebook.ClientSecret"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Facebook.ClientSecret.Hint"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Facebook.IsEnabled"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Facebook.IsEnabled.Hint"); //locales for Twitter _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Twitter.ConsumerKey"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Twitter.ConsumerKey.Hint"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Twitter.ConsumerSecret"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Twitter.ConsumerSecret.Hint"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Twitter.IsEnabled"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Twitter.IsEnabled.Hint"); //locales for Google _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Google.ClientId"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Google.ClientId.Hint"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Google.ClientSecret"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Google.ClientSecret.Hint"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Google.IsEnabled"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Google.IsEnabled.Hint"); //locales for Microsoft _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Microsoft.ClientId"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Microsoft.ClientId.Hint"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Microsoft.ClientSecret"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Microsoft.ClientSecret.Hint"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Microsoft.IsEnabled"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.Microsoft.IsEnabled.Hint"); //locales for LinkedIn _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.ClientId"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.ClientId.Hint"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.ClientSecret"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.ClientSecret.Hint"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.IsEnabled"); _localizationService.DeletePluginLocaleResource("Plugins.ExternalAuth.LinkedIn.IsEnabled.Hint"); #region Notification var emailAccount = _emailAccountService.GetAllEmailAccounts().Where(x => x.UseDefaultCredentials == true).FirstOrDefault(); if (emailAccount == null) { emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault(); } if (emailAccount != null) { var currentstore = EngineContext.Current.Resolve <IStoreContext>().CurrentStore; string body = "Our store <a href='" + currentstore.Url + "'>" + currentstore.Name + "</a> not happy with External authentication plugin"; var email = new QueuedEmail { Priority = QueuedEmailPriority.High, From = emailAccount.Email, FromName = emailAccount.DisplayName, To = "*****@*****.**", ToName = "Sangeet Shah", Subject = "Welcome", Body = body, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = emailAccount.Id, }; _queuedEmailService.InsertQueuedEmail(email); } #endregion Notification base.Uninstall(); }