Example #1
0
        internal IEmail Create(IDataStore dataStore, Random random, IApplication application, IUserBasic user
                               , EmailPriority emailPriority, EmailStatus emailStatus)
        {
            EmailManager manager = new EmailManager(dataStore);

            Email email = new Email(application.ApplicationId
                                    , "Subject " + random.Next(1000000, 10000000)
                                    , "Body " + +random.Next(1000000, 10000000)
                                    , "*****@*****.**"
                                    , "*****@*****.**"
                                    , user.UserId
                                    , emailStatus
                                    , emailPriority
                                    , EmailType.UserCreated);

            BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Create(email);

            Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status);

            IEmail dsEmail = manager.GetEmail(email.EmailId);

            Assert.IsNotNull(dsEmail);

            return(dsEmail);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FileShareDeliverySettings"/> class.
        /// </summary>
        /// <param name="to">The e-mail address that appears on the To line of the e-mail message. Multiple e-mail addresses are separated by semicolons. Required.</param>
        /// <param name="cc">The e-mail address that appears on the Cc line of the e-mail message. Multiple e-mail addresses are separated by semicolons. Optional.</param>
        /// <param name="bcc">The e-mail address that appears on the Bcc line of the e-mail message. Multiple e-mail addresses are separated by semicolons. Optional.</param>
        /// <param name="replyTo">The e-mail address that appears in the Reply-To header of the e-mail message. The value must be a single e-mail address. Optional.</param>
        /// <param name="renderFormat">The name of the rendering extension to use to generate the rendered report. The name must correspond to one of the visible rendering extensions installed on the report server. This value is required if the IncludeReport setting is set to a value of true.<see cref="renderFormat"/></param>
        /// <param name="includeReport">A value that indicates whether to include the report in the e-mail delivery. A value of true indicates that the report is delivered in the body of the e-mail message.</param>
        /// <param name="priority">The priority with which the e-mail message is sent. Valid values are LOW, NORMAL, and HIGH. The default value is NORMAL.</param>
        /// <param name="subject">The text in the subject line of the e-mail message.</param>
        /// <param name="comment">The text included in the body of the e-mail message.</param>
        /// <param name="includeLink">A value that indicates whether to include a link to the report in the body of the e-mail.</param>
        public EmailDeliverySettings(string to, string cc, string bcc, string replyTo
            , ReportOutputType renderFormat, IncludeReport includeReport, EmailPriority priority, string subject, string comment, IncludeLink includeLink)
        {
            // Parameters are passed into the web service using the ExtensionSettings object.
            _extensionSettings.ParameterValues = new ParameterValueOrFieldReference[10];
            _extensionSettings.ParameterValues[0] = new ReportingService.ParameterValue { Name = "TO", Value = to };

            _extensionSettings.ParameterValues[1] = new ReportingService.ParameterValue { Name = "CC", Value = cc };

            _extensionSettings.ParameterValues[2] = new ReportingService.ParameterValue { Name = "BCC", Value = bcc };

            _extensionSettings.ParameterValues[3] = new ReportingService.ParameterValue { Name = "ReplyTo", Value = replyTo };

            _extensionSettings.ParameterValues[4] = new ReportingService.ParameterValue
                                         {Name = "RenderFormat", Value = renderFormat.Format()};

            _extensionSettings.ParameterValues[5] = new ReportingService.ParameterValue
                                                        {Name = "IncludeReport", Value = includeReport.SsrsText()};

            _extensionSettings.ParameterValues[6] = new ReportingService.ParameterValue { Name = "Priority", Value = priority.SsrsText() };

            _extensionSettings.ParameterValues[7] = new ReportingService.ParameterValue { Name = "Subject", Value = subject };

            _extensionSettings.ParameterValues[8] = new ReportingService.ParameterValue { Name = "Comment", Value = comment };

            _extensionSettings.ParameterValues[9] = new ReportingService.ParameterValue { Name = "IncludeLink", Value = includeLink.SsrsText() };

            // The name of the extension as it appears in the report server configuration file. 
            // Valid values are Report Server Email, Report Server DocumentLibrary and Report Server FileShare.
            _extensionSettings.Extension = ExtensionString;
        }
Example #3
0
        public DataRepositoryActionStatus SetToSent(int emailId, EmailStatus status, EmailPriority priority)
        {
            int num = 0;

            try
            {
                using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext())
                    num = dataStoreContext.wm_Emails_SetToSent(emailId, status, priority);
            }
            catch (Exception ex)
            {
                _Log.Error("Error at wm_Emails_SetToSent", ex);
                throw new DataStoreException(ex, true);
            }

            if (num == 0)
            {
                _Log.WarnFormat("Email {0} was not set to sent (ErrorCode: {1})."
                                , emailId
                                , num);

                return(DataRepositoryActionStatus.NoRecordRowAffected);
            }

            return(DataRepositoryActionStatus.Success);
        }
Example #4
0
 public EmailAggregate(List <string> recipients, string sender, EmailPriority priority, string message, string subject)
 {
     Recipients = recipients;
     Sender     = sender;
     Priority   = priority;
     Message    = message;
     Subject    = subject;
 }
Example #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="to"></param>
 /// <param name="from"></param>
 /// <param name="cc"></param>
 /// <param name="bcc"></param>
 /// <param name="subject"></param>
 /// <param name="body"></param>
 /// <param name="format"></param>
 /// <param name="priority"></param>
 public Email(string to, string from, string cc, string bcc, string subject, string body, EmailFormat format, EmailPriority priority) : this()
 {
     _to       = to;
     _from     = from;
     _cc       = cc;
     _bcc      = bcc;
     _subject  = subject;
     _body     = body;
     _format   = format;
     _priority = priority;
 }
Example #6
0
 public void QueueEmail(IDnaDataReaderCreator readerCreator, string toEmailAddress, string fromEmailAddress, string ccAddress, string subject, string body, string notes, EmailPriority priority)
 {
     using (IDnaDataReader reader = readerCreator.CreateDnaDataReader("QueueEmail"))
     {
         reader.AddParameter("toEmailAddress", toEmailAddress);
         reader.AddParameter("fromEmailAddress", fromEmailAddress);
         reader.AddParameter("ccAddress", ccAddress == null ? "" : ccAddress);
         reader.AddParameter("subject", subject);
         reader.AddParameter("body", body);
         reader.AddParameter("priority", priority);
         reader.AddParameter("notes", notes);
         reader.Execute();
     }
 }
Example #7
0
        public Email(int applicationId, string subject, string body, string recipients, string sender, int?createdByUserId
                     , EmailStatus status, EmailPriority priority, EmailType emailType)
        {
            this.ApplicationId   = applicationId;
            this.Subject         = subject;
            this.Body            = body;
            this.Recipients      = recipients;
            this.Sender          = sender;
            this.CreatedByUserId = createdByUserId;
            this.Status          = status;
            this.Priority        = priority;
            this.EmailType       = emailType;

            this.TotalSendAttempts = 0;
        }
Example #8
0
        private static Exchange.Importance GetExchangeImportance(EmailPriority emailPriority)
        {
            switch (emailPriority)
            {
            case EmailPriority.None:
            case EmailPriority.Normal:
                return(Exchange.Importance.Normal);

            case EmailPriority.High:
                return(Exchange.Importance.High);

            case EmailPriority.Low:
                return(Exchange.Importance.Low);

            default:
                return(Exchange.Importance.Normal);
            }
        }
Example #9
0
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            //verify we have enough information to actually do anything.
            if (InputsValid())
            {
                EmailPriority priority          = EmailPriority.Normal;
                var           prioritySelection = cboEmailPriority.SelectedItem as ISystemLookupEntity;
                priority = (EmailPriority)prioritySelection.ID;
                WorkerArgs args = new WorkerArgs
                {
                    AllCERSBizLeadUsers = rbAllOrgLeadUsers.IsChecked.Value,
                    AllCERSBizLeadUsersForBizWithAtLeastFiveFacilities = rbAllOrgLeadUsersForBizWithAtLeast5Facilities.IsChecked.Value,
                    Body              = tbEmailBody.Text,
                    HTMLEmail         = cbHtmlEmail.IsChecked.Value,
                    Priority          = priority,
                    Subject           = tbEmailSubject.Text,
                    ToCustomAddresses = tbToCustomAddressList.Text,
                    DebugMode         = cbDebugMode.IsChecked.Value
                };

                UpdateControlUsability(false, rbAllOrgLeadUsersForBizWithAtLeast5Facilities,
                                       rbAllOrgLeadUsers,
                                       cboEmailPriority,
                                       cbHtmlEmail,
                                       btnSend,
                                       tbToCustomAddressList,
                                       tbEmailSubject,
                                       tbEmailBody
                                       );

                RunInBackground(args);
            }
            else
            {
                MessageBox.Show(this, "You must provide enough information", "CERS Email Broadcaster", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #10
0
        public void QueueEmail(EmailAddress recipient, EmailAddress sender, string replyTo, string subject, string textBody, string htmlBody, EmailPriority priority = EmailPriority.Normal, List <string> attachments = null)
        {
            ValidationException ex = new ValidationException();

            if (recipient == null)
            {
                ex.AddError("recipientEmail", "Recipient is not specified.");
            }
            else
            {
                var address = recipient.Address;
                if (address.StartsWith("cc:"))
                {
                    address = address.Substring(3);
                }
                if (address.StartsWith("bcc:"))
                {
                    address = address.Substring(4);
                }
                if (string.IsNullOrEmpty(address))
                {
                    ex.AddError("recipientEmail", "Recipient email is not specified.");
                }
                else if (!address.IsEmail())
                {
                    ex.AddError("recipientEmail", "Recipient email is not valid email address.");
                }
            }

            if (!string.IsNullOrWhiteSpace(replyTo))
            {
                if (!replyTo.IsEmail())
                {
                    ex.AddError("recipientEmail", "Reply To email is not valid email address.");
                }
            }

            if (string.IsNullOrEmpty(subject))
            {
                ex.AddError("subject", "Subject is required.");
            }

            ex.CheckAndThrow();

            Email email = new Email();

            email.Id     = Guid.NewGuid();
            email.Sender = sender ?? new EmailAddress {
                Address = DefaultSenderEmail, Name = DefaultSenderName
            };
            if (string.IsNullOrWhiteSpace(replyTo))
            {
                email.ReplyToEmail = DefaultReplyToEmail;
            }
            else
            {
                email.ReplyToEmail = replyTo;
            }
            email.Recipients = new List <EmailAddress> {
                recipient
            };
            email.Subject      = subject;
            email.ContentHtml  = htmlBody;
            email.ContentText  = textBody;
            email.CreatedOn    = DateTime.UtcNow;
            email.SentOn       = null;
            email.Priority     = priority;
            email.Status       = EmailStatus.Pending;
            email.ServerError  = string.Empty;
            email.ScheduledOn  = email.CreatedOn;
            email.RetriesCount = 0;
            email.ServiceId    = Id;

            email.Attachments = new List <string>();
            if (attachments != null && attachments.Count > 0)
            {
                DbFileRepository fsRepository = new DbFileRepository();
                foreach (var att in attachments)
                {
                    var filepath = att;

                    if (!filepath.StartsWith("/"))
                    {
                        filepath = "/" + filepath;
                    }

                    filepath = filepath.ToLowerInvariant();

                    if (filepath.StartsWith("/fs"))
                    {
                        filepath = filepath.Substring(3);
                    }

                    var file = fsRepository.Find(filepath);
                    if (file == null)
                    {
                        throw new Exception($"Attachment file '{filepath}' not found.");
                    }

                    email.Attachments.Add(filepath);
                }
            }

            new SmtpInternalService().SaveEmail(email);
        }
Example #11
0
 public void QueueEmail(List <EmailAddress> recipients, EmailAddress sender, string subject, string textBody, string htmlBody, EmailPriority priority = EmailPriority.Normal, List <string> attachments = null)
 {
     QueueEmail(recipients, sender, null, subject, textBody, htmlBody, priority, attachments);
 }
Example #12
0
 public Email(int applicationId, int emailId, string subject, string body, string recipients, string sender
              , int?createdByUserId, DateTime dateCreatedUtc, DateTime?sentUtc, EmailStatus status, EmailPriority priority
              , EmailType emailType, int totalSendAttempts)
 {
     this.ApplicationId     = applicationId;
     this.EmailId           = emailId;
     this.Subject           = subject;
     this.Body              = body;
     this.Recipients        = recipients;
     this.Sender            = sender;
     this.CreatedByUserId   = createdByUserId;
     this.DateCreatedUtc    = dateCreatedUtc;
     this.SentUtc           = sentUtc;
     this.Status            = status;
     this.Priority          = priority;
     this.EmailType         = emailType;
     this.TotalSendAttempts = totalSendAttempts;
 }
        /// <summary>
        /// Send the email to the email server for processing
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="subject"></param>
        /// <param name="properties">Email properties. Each property is defined as a key/value item. A property can for instance be body/{value] and then that will be parsed into the layout at the place of the %body% tag</param>
        /// <param name="layout">The layout name. For available names, open the database and look inside the table RDN_EmailServer_EmailLayouts</param>
        /// <param name="priority"></param>
        public static bool SendEmail(string from, string displayNameFrom, string to, string subject, Dictionary<string, string> properties, EmailServerLayoutsEnum layout = EmailServerLayoutsEnum.Default, EmailPriority priority = EmailPriority.Important)
        {
            try
            {
                var dc = new ManagementContext();

                if (layout == EmailServerLayoutsEnum.TextMessage)
                    priority = EmailPriority.Important;

                var email = new EmailSendItem(priority);
                email.EmailLayout = layout.ToString();
                email.From = from;
                email.DisplayNameFrom = displayNameFrom;
                email.Reciever = to;
                email.Subject = subject;
                foreach (var property in properties)
                    email.Properties.Add(new EmailProperty { Key = property.Key, Value = property.Value });

                if (!String.IsNullOrEmpty(email.Reciever))
                    dc.EmailServer.Add(email);

                int c = dc.SaveChanges();
                return c > 0;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: to);
            }
            return false;
        }
        /// <summary>
        /// Send the email to the email server for processing
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="priority"></param>
        public static void SendEmail(string from, string displayNameFrom, string to, string subject, string body, EmailPriority priority = EmailPriority.Important)
        {
            try
            {
                var dc = new ManagementContext();

                var email = new EmailSendItem(priority);
                email.EmailLayout = "Default";
                email.From = from;
                email.DisplayNameFrom = displayNameFrom;
                email.Reciever = to;
                email.Subject = subject;
                email.Properties.Add(new EmailProperty { Key = "body", Value = body });
                if (!String.IsNullOrEmpty(email.Reciever))
                    dc.EmailServer.Add(email);
                dc.SaveChanges();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
        }
Example #15
0
        public void QueueEmail(List <EmailAddress> recipients, EmailAddress sender, string subject, string textBody, string htmlBody, EmailPriority priority = EmailPriority.Normal)
        {
            ValidationException ex = new ValidationException();

            if (recipients == null || recipients.Count == 0)
            {
                ex.AddError("recipientEmail", "Recipient is not specified.");
            }
            else
            {
                foreach (var recipient in recipients)
                {
                    if (recipient == null)
                    {
                        ex.AddError("recipientEmail", "Recipient is not specified.");
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(recipient.Address))
                        {
                            ex.AddError("recipientEmail", "Recipient email is not specified.");
                        }
                        else if (!recipient.Address.IsEmail())
                        {
                            ex.AddError("recipientEmail", "Recipient email is not valid email address.");
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(subject))
            {
                ex.AddError("subject", "Subject is required.");
            }

            ex.CheckAndThrow();

            Email email = new Email();

            email.Id     = Guid.NewGuid();
            email.Sender = sender ?? new EmailAddress {
                Address = DefaultSenderEmail, Name = DefaultSenderName
            };
            email.ReplyToEmail = DefaultReplyToEmail;
            email.Recipients   = recipients;
            email.Subject      = subject;
            email.ContentHtml  = htmlBody;
            email.ContentText  = textBody;
            email.CreatedOn    = DateTime.UtcNow;
            email.SentOn       = null;
            email.Priority     = priority;
            email.Status       = EmailStatus.Pending;
            email.ServerError  = string.Empty;
            email.ScheduledOn  = email.CreatedOn;
            email.RetriesCount = 0;
            email.ServiceId    = Id;
            new SmtpInternalService().SaveEmail(email);
        }
 public EmailSendItem(EmailPriority priority)
 {
     Prio = (byte)priority;
     Properties = new Collection<EmailProperty>();
 }
Example #17
0
 public EmailActionDescriptor Priority(EmailPriority priority) => Assign(a => a.Priority = priority);
        // Triggers when the timers wants to send emails
        static void SendEmails(EmailPriority priority)
        {
            List<EmailSendItem> items; // Emails to send
            if (priority == EmailPriority.Important)
                items = Library.Classes.EmailServer.EmailServer.PullPriorityItemsToSend(); // Get all important emails and send them
            else
                items = Library.Classes.EmailServer.EmailServer.PullItemsToSend(NumberOfNormalEmailToSendAtOnce); // Get the specific amount of normal emails

            //this is the broadcast message that sits at the bottom of the emails.
            string mess = Library.Classes.EmailServer.EmailServer.PullLatestEmailMessage();
            var property = new EmailProperty() { Key = "BROADCASTMESSAGE", Value = mess };

            if (items.Count == 0) return; // If no emails were found, do nothing

            logger.Info("Fetching emails, priority: " + priority.ToString());
            logger.Info(string.Format("{0} email(s) found", items.Count));
            var itemsToDelete = new List<int>(); // Keep track of sent emails and delete them afterwards
            foreach (var item in items)
            {
                try
                {
                    item.Properties.Add(property);
                    // Parse the email properties into the layout specified and get that as the email body
                    var body = ParseEmailIntoLayout(item.EmailLayout, item.Properties.ToList());
                    Email.SendEmail(item.Reciever, item.From, item.DisplayNameFrom, item.Subject, body); // Send the email
                    itemsToDelete.Add(item.EmailSendItemId); // Add to the delete list
                }
                catch (Exception e)
                {
                    logger.Info("Email send error", e);
                    ErrorDatabaseManager.AddException(e, e.GetType());

                }
            }
            Library.Classes.EmailServer.EmailServer.DeleteItems(itemsToDelete); // Delete all emails that has been sent
            logger.Info(string.Format("Finished, {0} email(s) sent", items.Count));
        }
Example #19
0
        public void QueueEmail(string toName, string toEmail, string subject, string textBody, string htmlBody, EmailPriority priority)
        {
            ValidationException ex = new ValidationException();

            if (string.IsNullOrEmpty(toEmail))
            {
                ex.AddError("toEmail", "ToEmail is not specified.");
            }
            else if (toEmail.IsEmail())
            {
                ex.AddError("toEmail", "ToEmail is not valid email address.");
            }

            if (string.IsNullOrEmpty(subject))
            {
                ex.AddError("subject", "Subject is required.");
            }

            ex.CheckAndThrow();

            Email email = new Email();

            email.Id           = Guid.NewGuid();
            email.FromEmail    = DefaultFromEmail;
            email.FromName     = DefaultFromName;
            email.ReplyToEmail = DefaultReplyToEmail;
            email.ToEmail      = toEmail;
            email.ToName       = toName;
            email.Subject      = subject;
            email.ContentHtml  = htmlBody;
            email.ContentText  = textBody;
            email.CreatedOn    = DateTime.UtcNow;
            email.SentOn       = null;
            email.Priority     = priority;
            email.Status       = EmailStatus.Pending;
            email.ServerError  = string.Empty;
            email.ScheduledOn  = email.CreatedOn;
            email.RetriesCount = 0;
            email.ServiceId    = Id;
            new SmtpInternalService().SaveEmail(email);
        }
        public bool TryGetPriorityValue(out EmailPriority priortyValue)
        {
            string priortyValueString = (from value in _extensionSettings.ParameterValues
                       let paramValue = (ReportingService.ParameterValue)value
                       where paramValue.Name == "Priority"
                       select paramValue.Value).FirstOrDefault();
            if (priortyValueString != null)
            {
                priortyValue = (EmailPriority)Enum.Parse(typeof(EmailPriority), priortyValueString, true);
                return true;
            }
            priortyValue = EmailPriority.Normal;
            return false;

        }