Пример #1
0
        public async Task<SendEmailDomain> SendEmailAsync(SendEmailDomain email)
        {
            string emailAddress = email.Address;
            string emailDisplayName = email.DisplayName;

            // Send email
            var emailToSend = new Email(email.Subject, email.Body, ContentType.Html, new EmailAddress(emailAddress, emailDisplayName));
            emailToSend.To.Add(new EmailAddress(email.Emails.First(), emailDisplayName)); //Email must always have a valid recipient
            emailToSend.Headers.AddRange(email.Emails); // Must always add to headers for utilizing send-grid api

            await _mailerRepository.SendMail(emailToSend);

            return email;
        }
Пример #2
0
        // POST /api/email
        public async Task<HttpResponseMessage> Post(SendEmailModel sendEmailModel)
        {
            var email = new SendEmailDomain
            {
                Address = _settings.EmailAddressInfo,
                DisplayName = Emails.SenderDisplayName,
                UserId = UserId,
                Body = sendEmailModel.Body,
                Emails = sendEmailModel.Emails,
                Subject = sendEmailModel.Subject
            };

            await _emailSender.SendEmailAsync(email);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Пример #3
0
        public async Task<SendEmailDomain> SendAndLogEmailAsync(SendEmailDomain email)
        {
            string emailAddress = email.Address;
            string emailDisplayName = email.DisplayName;

            // Send email
            var emailToSend = new Email(email.Subject, email.Body, ContentType.Html, new EmailAddress(emailAddress, emailDisplayName));
            emailToSend.To.Add(new EmailAddress(email.Emails.First(), emailDisplayName)); //Email must always have a valid recipient
            emailToSend.Headers.AddRange(email.Emails); // Must always add to headers for utilizing send-grid api

            await _mailerRepository.SendMail(emailToSend);

            email.Id = ((int)email.Template) + GetUtcTimestamp();
            email.Created = DateTime.UtcNow;

            // Log sent email
            SendEmailEntity entity = _mapper.Map<SendEmailDomain, SendEmailEntity>(email);
            await _sendEmailRepository.AddAsync(entity);

            return email;
        }
Пример #4
0
        private void Trace(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, object[] args = null)
        {
            if (eventType != TraceEventType.Critical && eventType != TraceEventType.Error) return;

            Match match = InstanceIdFormat.Match(RoleEnvironment.CurrentRoleInstance.Id);
            string roleId = match.Success ? match.Groups[1].Value : string.Empty;

            try
            {
                string subject = string.Format("{0}[{1}] failure: {2}",
                    RoleEnvironment.CurrentRoleInstance.Role.Name,
                    roleId,
                    CleanupFormatString(format));

                var message = new StringBuilder();
                //
                message.AppendFormat("Environment: {0}<br/>", Environment);
                //
                message.AppendLine("Event Message:<br/>");
                message.AppendLine("<pre>");
                message.AppendLine(args == null ? format : string.Format(format, args));
                message.AppendLine("</pre>");
                //
                message.AppendFormat("Event Source: {0}<br/>", source);
                message.AppendFormat("Event Type: {0}<br/>", eventType);
                message.AppendFormat("Event ID: {0}<br/>", id);
                //
                message.AppendLine("Event Call Stack:<br/>");
                message.AppendLine("<pre>");
                message.AppendLine(eventCache.Callstack);
                message.AppendLine("</pre>");
                //
                message.AppendFormat("DateTime: {0}<br/>", eventCache.DateTime);
                message.AppendFormat("Timestamp: {0}<br/>", eventCache.Timestamp);
                message.AppendFormat("Version: {0}<br/>", _portalVersion);
                message.AppendFormat("Environment Machine: {0}<br/>", System.Environment.MachineName);
                message.AppendFormat("Environment User: {0}<br/>", System.Environment.UserName);
                //
                message.AppendFormat("Process ID: {0}<br/>", eventCache.ProcessId);
                message.AppendFormat("Thread ID: {0}<br/>", eventCache.ThreadId);
                Process process = Process.GetCurrentProcess();
                message.AppendFormat("Process Threads Count: {0}<br/>", process.Threads.Count);
                message.AppendFormat("Process Start Time: {0}<br/>", process.StartTime);
                message.AppendFormat("Process Working Set: {0}<br/>", process.WorkingSet64);
                //
                if (HttpContext.Current != null)
                {
                    HttpRequest request = HttpContext.Current.Request;

                    message.AppendFormat("HTTP Request HTTP Method: {0}<br/>", request.HttpMethod);
                    message.AppendFormat("HTTP Request URL: {0}<br/>", request.Url);
                    message.AppendFormat("HTTP Request Query String: {0}<br/>", request.QueryString);
                    message.AppendFormat("HTTP Request User Agent: {0}<br/>", request.UserAgent);
                    message.AppendFormat("HTTP Request User Host Address: {0}<br/>", request.UserHostAddress);
                    message.AppendFormat("HTTP Request Is Authenticated: {0}<br/>", request.IsAuthenticated);
                    message.AppendFormat("HTTP Request User: {0}<br/>", HttpContext.Current.User.Identity.Name);
                    HttpCookieCollection cookies = request.Cookies;
                    if (cookies.Count > 0)
                    {
                        message.AppendFormat("HTTP Request Cookies: {0}<br/>", cookies
                            .AllKeys
                            .Select(p =>
                            {
                                HttpCookie cookie = cookies.Get(p);
                                return cookie != null ? string.Format("{0}={1}", p, cookie.Value) : string.Empty;
                            })
                            .Aggregate((p, q) => p + "; " + q));
                    }
                    message.AppendFormat("HTTP Request ContentType: {0}<br/>", request.ContentType);

                    if (request.Form.Count > 0)
                    {
                        message.AppendLine("HTTP Request Form Values:<br/>");
                        foreach (string key in request.Form.AllKeys)
                        {
                            message.AppendFormat("  {0}={1}<br/>", key, request.Form.Get(key));
                        }
                    }
                }

                // Build email message
                var email = new SendEmailDomain
                {
                    Address = _settings.EmailAddressAlerts,
                    DisplayName = Emails.SenderDisplayName,
                    Body = message.ToString(),
                    Emails = new List<string> { _settings.EmailAddressErrors },
                    Subject = subject
                };

                // Send
                _emailSender.SendEmailAsync(email).Wait();
            }
            catch (Exception e)
            {
                Debug.Fail(string.Format("Unable to send e-mail: {0}", e));
            }
        }
Пример #5
0
        public async Task<ActionResult> PostFeedback(FeedbackModel model)
        {
            var email = new SendEmailDomain
            {
                Address = model.Email,
                UserId = UserId,
                Body = model.Message,
                Emails = new List<string> { _settings.EmailAddressSupport },
                Subject = Emails.SubjectFeedback
            };

            if (!ModelState.IsValid)
            {
                return View("Feedback");
            }

            try
            {
                await _emailSenderService.SendEmailAsync(email);
            }
            catch (Exception)
            {
                return View(new FeedbackResultModel { Status = FeedbackStatus.Error });
            }

            return View(new FeedbackResultModel { Status = FeedbackStatus.Success });
        }
        public async Task SendFirstProjectEmail(string userId, string userAgent)
        {
            if (!_settings.EmailNotifications)
            {
                return;
            }

            string template;
            EmailTemplate templateId;
            ProductType product = _productIdExtractor.Get(userAgent);

            switch (product)
            {
                case ProductType.ImageShack:
                    template = PortalResources.UserRegistrationImageshack;
                    templateId = EmailTemplate.FirstProjectExtension;
                    break;

                case ProductType.CicIPad:
                case ProductType.CicMac:
                case ProductType.CicPc:
                    template = PortalResources.ProjectFirstCic;
                    templateId = EmailTemplate.FirstProjectCic;
                    break;

                case ProductType.TaggerAndroid:
                case ProductType.TaggerIPhone:
                    template = PortalResources.ProjectFirstTagger;
                    templateId = EmailTemplate.FirstProjectOtherProducts;
                    break;

                case ProductType.Standalone:
                    template = PortalResources.UserRegistration;
                    templateId = EmailTemplate.Registration;
                    break;

                default:
                    return;
            }

            bool emailAlreadySendOnce = await CheckEmailBeenSend(userId, templateId);
            if (emailAlreadySendOnce)
            {
                return;
            }

            DomainUser user = await _userService.GetAsync(userId);
            if (user == null || string.IsNullOrEmpty(user.Email))
            {
                return;
            }

            var email = new SendEmailDomain
            {
                Body = string.Format(template, user.Name),
                Address = _settings.EmailAddressInfo,
                DisplayName = Emails.SenderDisplayName,
                Subject = Emails.SubjectFirstTag,
                Emails = new List<string> { user.Email },
                UserId = userId,
                Template = templateId
            };

            await _emailSenderService.SendAndLogEmailAsync(email);
        }
        public Task SendRegistrationEmailAsync(DomainUser user)
        {
            if (string.IsNullOrEmpty(user.Email) || !_settings.EmailNotifications)
            {
                return Task.FromResult(0);
            }

            switch (user.UserAgent)
            {
                case ProductType.CicPc:
                case ProductType.CicMac:
                case ProductType.CicIPad:
                case ProductType.TaggerAndroid:
                case ProductType.TaggerIPhone:
                case ProductType.YoutubePlayer:
                case ProductType.DailyMotion:
                case ProductType.Other:
                    break;

                default:
                    return Task.FromResult(0);
            }

            var email = new SendEmailDomain
            {
                Address = _settings.EmailAddressInfo,
                DisplayName = Emails.SenderDisplayName,
                Emails = new List<string> { user.Email },
                Subject = Emails.SubjectRegistration,
                UserId = user.Id,
                Body = string.Format(PortalResources.UserRegistration, user.Name)
            };

            // Send email on user registration
            return _emailSenderService.SendEmailAsync(email);
        }
        public Task SendVideoCommentNotificationAsync(DomainUser user, DomainProject project, DomainComment domainComment)
        {
            var email = new SendEmailDomain
            {
                Address = _settings.EmailAddressInfo,
                DisplayName = Emails.SenderDisplayName,
                Emails = new List<string> { user.Email },
                Subject = Emails.SubjectVideoComment,
                UserId = user.Id,
                Body = string.Format(PortalResources.VideoCommentNotification,
                    user.Name,
                    _userUriProvider.GetUri(domainComment.UserId),
                    domainComment.UserName,
                    _projectUriProvider.GetUri(project.Id),
                    project.Name,
                    domainComment.Body,
                    _settings.PortalUri)
            };

            // Send email on user registration
            return _emailSenderService.SendEmailAsync(email);
        }
        public async Task SendAbuseNotificationAsync(Watch project, DomainUser reporter)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            if (reporter == null)
            {
                throw new ArgumentNullException("reporter");
            }

            if (!_settings.EmailNotifications)
            {
                return;
            }

            string projectUri = _projectUriProvider.GetUri(project.Id);
            var email = new SendEmailDomain
            {
                Address = _settings.EmailAddressAlerts,
                DisplayName = Emails.SenderDisplayName,
                Emails = new List<string> { _settings.EmailAddressAbuse },
                Subject = string.Format(Emails.SubjectAbuseReport, projectUri),
                Body = string.Format(
                    PortalResources.AbuseReported,
                    reporter.Name,
                    _userUriProvider.GetUri(reporter.Id),
                    project.Name,
                    projectUri)
            };

            // Send email
            await _emailSenderService.SendEmailAsync(email);
        }
        public async Task SendPaymentNotificationAsync(DomainEvent billingEvent, DomainCompany company, DomainCharge charge)
        {
            if (billingEvent == null)
            {
                throw new ArgumentNullException("billingEvent");
            }

            if (company == null)
            {
                throw new ArgumentNullException("company");
            }

            if (charge == null)
            {
                throw new ArgumentNullException("charge");
            }

            if (!_settings.EmailNotifications)
            {
                return;
            }

            var email = new SendEmailDomain
            {
                Address = _settings.EmailAddressAlerts,
                DisplayName = Emails.SenderDisplayName,
                Emails = new List<string> { company.Email }
            };

            switch (billingEvent.Type)
            {
                case EventType.ChargeFailed:
                    email.Subject = Emails.SubjectPaymentFailed;
                    email.Body = string.Format(
                        PortalResources.PaymentFailed,
                        company.Name,
                        billingEvent.Id,
                        string.Format("{0} {1}", charge.AmountInCents*0.01, charge.Currency),
                        charge.Created);
                    break;

                case EventType.ChargeSucceeded:
                    email.Subject = Emails.SubjectPaymentCompleted;
                    email.Body = string.Format(
                        PortalResources.PaymentCompleted,
                        company.Name,
                        billingEvent.Id,
                        string.Format("{0} {1}", charge.AmountInCents*0.01, charge.Currency),
                        charge.Created);
                    break;

                case EventType.ChargeRefunded:
                    email.Subject = Emails.SubjectPaymentRefunded;
                    email.Body = string.Format(
                        PortalResources.PaymentRefunded,
                        company.Name,
                        billingEvent.Id,
                        string.Format("{0} {1}", charge.AmountInCents*0.01, charge.Currency),
                        charge.Created);
                    break;

                default:
                    return;
            }


            // Send email on user registration
            await _emailSenderService.SendEmailAsync(email);
        }
        public Task SendClientActivationEmailAsync(DomainPendingClient client)
        {
            if (string.IsNullOrEmpty(client.Email))
            {
                return Task.FromResult(0);
            }

            var email = new SendEmailDomain
            {
                Address = _settings.EmailAddressAlerts,
                DisplayName = Emails.SenderDisplayName,
                Emails = new List<string> { client.Email },
                Subject = Emails.SubjectRegistration,
                Body = string.Format(
                    PortalResources.ClientActivation,
                    client.ContactPerson,
                    client.Email,
                    _settings.PortalUri,
                    client.Id)
            };

            // Send email on user registration
            return _emailSenderService.SendEmailAsync(email);
        }