public Task SendEmailAsync(SmtpContext context, EmailMessage message)
        {
            Guard.ArgumentNotNull(() => context);
            Guard.ArgumentNotNull(() => message);

            var msg = this.BuildMailMessage(message);

            using (var client = context.ToSmtpClient())
            {
                return(client.SendMailAsync(msg));
            }
        }
        public void SendEmail(SmtpContext context, EmailMessage message)
        {
            Guard.ArgumentNotNull(() => context);
            Guard.ArgumentNotNull(() => message);

            var msg = this.BuildMailMessage(message);

            using (var client = context.ToSmtpClient())
            {
                client.Send(msg);
            }
        }
Exemplo n.º 3
0
        public void SendEmail(SmtpContext context, EmailMessage message)
        {
            Guard.ArgumentNotNull(() => context);
            Guard.ArgumentNotNull(() => message);

            using (var msg = this.BuildMailMessage(message))
            {
                using (var client = context.ToSmtpClient())
                {
                    client.Send(msg);
                }
            }
        }
Exemplo n.º 4
0
        public void SendEmail(SmtpContext context, EmailMessage message)
        {
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(message, nameof(message));

            using (var msg = this.BuildMailMessage(message))
            {
                using (var client = context.ToSmtpClient())
                {
                    client.Send(msg);
                }
            }
        }
Exemplo n.º 5
0
        public Task SendEmailAsync(SmtpContext context, EmailMessage message)
        {
            Guard.ArgumentNotNull(() => context);
            Guard.ArgumentNotNull(() => message);

            var client = context.ToSmtpClient();
            var msg = this.BuildMailMessage(message);

            return client.SendMailAsync(msg).ContinueWith(t =>
            {
                client.Dispose();
                msg.Dispose();
            });
        }
Exemplo n.º 6
0
        public async Task SendEmailAsync(SmtpContext context, EmailMessage message)
        {
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(message, nameof(message));

            using (var msg = this.BuildMailMessage(message))
            {
                using (var client = context.ToSmtpClient())
                {
                    ApplySettings(client);
                    await client.SendMailAsync(msg);
                }
            }
        }
        /// <summary>
        /// Executes a task
        /// </summary>
        public void Execute(TaskExecutionContext ctx)
        {
            var maxTries = 3;
            var queuedEmails = _queuedEmailService.SearchEmails(null, null, null, null, true, maxTries, false, 0, 10000);

            foreach (var qe in queuedEmails)
            {
                var bcc = String.IsNullOrWhiteSpace(qe.Bcc)
                            ? null
                            : qe.Bcc.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                var cc = String.IsNullOrWhiteSpace(qe.CC)
                            ? null
                            : qe.CC.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                try
                {
                    var smtpContext = new SmtpContext(qe.EmailAccount);

                    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));
                    }

                    if (cc != null)
                        msg.Cc.AddRange(cc.Where(x => x.HasValue()).Select(x => new EmailAddress(x)));

                    if (bcc != null)
                        msg.Bcc.AddRange(bcc.Where(x => x.HasValue()).Select(x => new EmailAddress(x)));

                    _emailSender.SendEmail(smtpContext, msg);

                    qe.SentOnUtc = DateTime.UtcNow;
                }
                catch (Exception exc)
                {
                    Logger.Error(string.Format("Error sending e-mail: {0}", exc.Message), exc);
                }
                finally
                {
                    qe.SentTries = qe.SentTries + 1;
                    _queuedEmailService.UpdateQueuedEmail(qe);
                }
            }
        }
Exemplo n.º 8
0
        public Task SendEmailAsync(SmtpContext context, EmailMessage message)
        {
            Guard.ArgumentNotNull(() => context);
            Guard.ArgumentNotNull(() => message);

            var client = context.ToSmtpClient();
            var msg    = this.BuildMailMessage(message);

            return(client.SendMailAsync(msg).ContinueWith(t =>
            {
                client.Dispose();
                msg.Dispose();
            }));
        }
        public Task SendEmailAsync(SmtpContext context, EmailMessage message)
        {
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(message, nameof(message));

            var client = context.ToSmtpClient();

            ApplySettings(client);
            var msg = this.BuildMailMessage(message);

            return(client.SendMailAsync(msg).ContinueWith(t =>
            {
                client.Dispose();
                msg.Dispose();
            }));
        }
Exemplo n.º 10
0
        private void SendCompletionEmail(DataImporterContext ctx)
        {
            var emailAccount = _emailAccountService.Value.GetDefaultEmailAccount();
            var smtpContext = new SmtpContext(emailAccount);
            var message = new EmailMessage();

            var store = _services.StoreContext.CurrentStore;
            var storeInfo = "{0} ({1})".FormatInvariant(store.Name, store.Url);
            var intro = _services.Localization.GetResource("Admin.DataExchange.Import.CompletedEmail.Body").FormatInvariant(storeInfo);
            var body = new StringBuilder(intro);
            var result = ctx.ExecuteContext.Result;

            if (result.LastError.HasValue())
            {
                body.AppendFormat("<p style=\"color: #B94A48;\">{0}</p>", result.LastError);
            }

            body.Append("<p>");

            body.AppendFormat("<div>{0}: {1} &middot; {2}: {3}</div>",
                T("Admin.Common.TotalRows"), result.TotalRecords,
                T("Admin.Common.Skipped"), result.SkippedRecords);

            body.AppendFormat("<div>{0}: {1} &middot; {2}: {3}</div>",
                T("Admin.Common.NewRecords"), result.NewRecords,
                T("Admin.Common.Updated"), result.ModifiedRecords);

            body.AppendFormat("<div>{0}: {1} &middot; {2}: {3}</div>",
                T("Admin.Common.Errors"), result.Errors,
                T("Admin.Common.Warnings"), result.Warnings);

            body.Append("</p>");

            message.From = new EmailAddress(emailAccount.Email, emailAccount.DisplayName);

            if (_contactDataSettings.Value.WebmasterEmailAddress.HasValue())
                message.To.Add(new EmailAddress(_contactDataSettings.Value.WebmasterEmailAddress));

            if (message.To.Count == 0 && _contactDataSettings.Value.CompanyEmailAddress.HasValue())
                message.To.Add(new EmailAddress(_contactDataSettings.Value.CompanyEmailAddress));

            if (message.To.Count == 0)
                message.To.Add(new EmailAddress(emailAccount.Email, emailAccount.DisplayName));

            message.Subject = T("Admin.DataExchange.Import.CompletedEmail.Subject").Text.FormatInvariant(ctx.Request.Profile.Name);

            message.Body = body.ToString();

            _emailSender.Value.SendEmail(smtpContext, message);

            //Core.Infrastructure.EngineContext.Current.Resolve<IQueuedEmailService>().InsertQueuedEmail(new QueuedEmail
            //{
            //	From = emailAccount.Email,
            //	FromName = emailAccount.DisplayName,
            //	To = message.To.First().Address,
            //	Subject = message.Subject,
            //	Body = message.Body,
            //	CreatedOnUtc = DateTime.UtcNow,
            //	EmailAccountId = emailAccount.Id,
            //	SendManually = true
            //});
            //_services.DbContext.SaveChanges();
        }
		public Task SendEmailAsync(SmtpContext context, EmailMessage message)
		{
			Guard.ArgumentNotNull(() => context);
			Guard.ArgumentNotNull(() => message);

			var msg = this.BuildMailMessage(message);

			using (var client = context.ToSmtpClient())
			{
				return client.SendMailAsync(msg);
			}
		}
		/// <summary>
		/// Sends a queued email
		/// </summary>
		/// <param name="queuedEmail">Queued email</param>
		/// <returns>Whether the operation succeeded</returns>
		public virtual bool SendEmail(QueuedEmail queuedEmail)
		{
			var result = false;

			try
			{
				var bcc = String.IsNullOrWhiteSpace(queuedEmail.Bcc) ? null : queuedEmail.Bcc.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
				var cc = String.IsNullOrWhiteSpace(queuedEmail.CC) ? null : queuedEmail.CC.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

				var smtpContext = new SmtpContext(queuedEmail.EmailAccount);

				var msg = new EmailMessage(
					new EmailAddress(queuedEmail.To, queuedEmail.ToName),
					queuedEmail.Subject,
					queuedEmail.Body,
					new EmailAddress(queuedEmail.From, queuedEmail.FromName));

				if (queuedEmail.ReplyTo.HasValue())
				{
					msg.ReplyTo.Add(new EmailAddress(queuedEmail.ReplyTo, queuedEmail.ReplyToName));
				}

				if (cc != null)
				{
					msg.Cc.AddRange(cc.Where(x => x.HasValue()).Select(x => new EmailAddress(x)));
				}

				if (bcc != null)
				{
					msg.Bcc.AddRange(bcc.Where(x => x.HasValue()).Select(x => new EmailAddress(x)));
				}

				_emailSender.SendEmail(smtpContext, msg);

				queuedEmail.SentOnUtc = DateTime.UtcNow;
				result = true;
			}
			catch (Exception exc)
			{
				_logger.Error(string.Concat(_localizationService.GetResource("Admin.Common.ErrorSendingEmail"), ": ", exc.Message), exc);
			}
			finally
			{
				queuedEmail.SentTries = queuedEmail.SentTries + 1;
				UpdateQueuedEmail(queuedEmail);
			}
			return result;
		}
Exemplo n.º 13
0
        private void SendCompletionEmail(DataExporterContext ctx, string zipPath)
        {
            var	emailAccount = _emailAccountService.Value.GetEmailAccountById(ctx.Request.Profile.EmailAccountId);

            if (emailAccount == null)
                emailAccount = _emailAccountService.Value.GetDefaultEmailAccount();

            var downloadUrl = "{0}Admin/Export/DownloadExportFile/{1}?name=".FormatInvariant(_services.WebHelper.GetStoreLocation(ctx.Store.SslEnabled), ctx.Request.Profile.Id);

            var languageId = ctx.Projection.LanguageId ?? 0;
            var smtpContext = new SmtpContext(emailAccount);
            var message = new EmailMessage();

            var storeInfo = "{0} ({1})".FormatInvariant(ctx.Store.Name, ctx.Store.Url);
            var intro =_services.Localization.GetResource("Admin.DataExchange.Export.CompletedEmail.Body", languageId).FormatInvariant(storeInfo);
            var body = new StringBuilder(intro);

            if (ctx.Result.LastError.HasValue())
            {
                body.AppendFormat("<p style=\"color: #B94A48;\">{0}</p>", ctx.Result.LastError);
            }

            if (ctx.IsFileBasedExport && File.Exists(zipPath))
            {
                var fileName = Path.GetFileName(zipPath);
                body.AppendFormat("<p><a href='{0}{1}' download>{2}</a></p>", downloadUrl, HttpUtility.UrlEncode(fileName), fileName);
            }

            if (ctx.IsFileBasedExport && ctx.Result.Files.Any())
            {
                body.Append("<p>");
                foreach (var file in ctx.Result.Files)
                {
                    body.AppendFormat("<div><a href='{0}{1}' download>{2}</a></div>", downloadUrl, HttpUtility.UrlEncode(file.FileName), file.FileName);
                }
                body.Append("</p>");
            }

            message.From = new EmailAddress(emailAccount.Email, emailAccount.DisplayName);

            if (ctx.Request.Profile.CompletedEmailAddresses.HasValue())
                message.To.AddRange(ctx.Request.Profile.CompletedEmailAddresses.SplitSafe(",").Where(x => x.IsEmail()).Select(x => new EmailAddress(x)));

            if (message.To.Count == 0 && _contactDataSettings.Value.CompanyEmailAddress.HasValue())
                message.To.Add(new EmailAddress(_contactDataSettings.Value.CompanyEmailAddress));

            if (message.To.Count == 0)
                message.To.Add(new EmailAddress(emailAccount.Email, emailAccount.DisplayName));

            message.Subject = _services.Localization.GetResource("Admin.DataExchange.Export.CompletedEmail.Subject", languageId)
                .FormatInvariant(ctx.Request.Profile.Name);

            message.Body = body.ToString();

            _emailSender.Value.SendEmail(smtpContext, message);

            //_queuedEmailService.Value.InsertQueuedEmail(new QueuedEmail
            //{
            //	From = emailAccount.Email,
            //	FromName = emailAccount.DisplayName,
            //	To = message.To.First().Address,
            //	Subject = message.Subject,
            //	Body = message.Body,
            //	CreatedOnUtc = DateTime.UtcNow,
            //	EmailAccountId = emailAccount.Id,
            //	SendManually = true
            //});
            //_dbContext.SaveChanges();
        }
Exemplo n.º 14
0
        public virtual bool SendEmail(QueuedEmail queuedEmail)
        {
            var result = false;

            try
            {
                var smtpContext = new SmtpContext(queuedEmail.EmailAccount);
                var msg = ConvertEmail(queuedEmail);

                _emailSender.SendEmail(smtpContext, msg);

                queuedEmail.SentOnUtc = DateTime.UtcNow;
                result = true;
            }
            catch (Exception exc)
            {
                Logger.Error(string.Concat(T("Admin.Common.ErrorSendingEmail"), ": ", exc.Message), exc);
            }
            finally
            {
                queuedEmail.SentTries = queuedEmail.SentTries + 1;
                UpdateQueuedEmail(queuedEmail);
            }

            return result;
        }