示例#1
0
        private void SendInvitationButton_Click(object sender, System.EventArgs e)
        {
            //Init Async call
            ASyncMailing      mail         = new ASyncMailing();
            ASyncMailingState mailingState = new ASyncMailingState(mail, Session.SessionID);
            AsyncCallback     cb           = new AsyncCallback(MailingCallback);

            // Build message to send
            EmailingMessage message;

            message           = new EmailingMessage();
            message.FromEmail = FromTextBox.Text;
            message.FromName  = FromNameTextbox.Text;
            message.Subject   = SubjectTextBox.Text;
            message.Body      = HttpUtility.HtmlDecode(MailingCKEditor.Text);
            message.Format    = EmailFormat.Html;

            // Dummy session variable to init the session in case
            // it was not initialized
            Session["IamADummy"] = "StartIt";

            // Start the mailing
            mail.BeginMailIt(Session.SessionID, SurveyId,
                             AnonymousEntriesCheckBox.Checked, MailingListTextBox.Text,
                             message, cb, mailingState);

            // Open the poll page while the mailing continues
            UINavigator.NavigateToMailingPoll(SurveyId, MenuIndex);
        }
示例#2
0
        public static void SendMail(string ToEmail, string Body, string Subject = "")
        {
            try
            {
                if (string.IsNullOrEmpty(Subject))
                {
                    Subject = EmailConfig.PALEmailSubject;
                }

                IEmailing       emailing = EmailingFactory.Create();
                EmailingMessage mail     = new EmailingMessage();
                mail.FromEmail = EmailConfig.PALEmailSMTPServerAuthUserName;
                mail.Format    = EmailFormat.Html;
                mail.Body      = Body;
                mail.Subject   = Subject;
                if (EmailConfig.PALEmailMode.ToUpper() == "TEST")
                {
                    mail.ToEmail = EmailConfig.PALEmailTo;
                }
                else
                {
                    mail.ToEmail = ToEmail;
                }
                emailing.SendEmail(mail);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void RemindRecipients(int surveyId)
 {
     while (true)
     {
         IEmailing       mailService = EmailingFactory.Create();
         EmailingMessage message     = new EmailingMessage();
         message.FromEmail = "*****@*****.**";
         message.Subject   = DateTime.Now.ToString();
         message.Body      = "ok";
         message.ToEmail   = "*****@*****.**";
         mailService.SendEmail(message);
         System.Threading.Thread.Sleep(10000);                 // 10 seconds wait
     }
 }
示例#4
0
        public static ResponseViewModel SendMail(string ToEmail, string Body, string Subject = "", string EmailFrom = "", byte[] attachmentData = null, string fileName = "", string fileType = "")
        {
            ResponseViewModel res = new ResponseViewModel();

            try
            {
                if (string.IsNullOrEmpty(Subject))
                {
                    Subject = EmailConfig.PALEmailSubject;
                }

                IEmailing       emailing = EmailingFactory.Create();
                EmailingMessage mail     = new EmailingMessage();
                mail.FromEmail = (!string.IsNullOrEmpty(EmailFrom) ? EmailFrom : EmailConfig.PALEmailSMTPServerAuthUserName);
                mail.Format    = EmailFormat.Html;
                mail.Body      = Body;
                mail.Subject   = Subject;

                if (attachmentData != null && attachmentData.Length > 0)
                {
                    mail.AttachmentList = new List <System.Net.Mail.Attachment>();
                    MemoryStream ms = new MemoryStream(attachmentData);
                    System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(ms, fileName, fileType);
                    mail.AttachmentList.Add(attachment);
                }

                if (EmailConfig.PALEmailMode.ToUpper() == "TEST")
                {
                    mail.ToEmail = EmailConfig.PALEmailTo;
                }
                else
                {
                    mail.ToEmail = ToEmail;
                }
                emailing.SendEmail(mail);

                res.Status  = "SUCCESS";
                res.Message = "";
            }
            catch (Exception ex)
            {
                res.Status  = "FAIL";
                res.Message = "SEND ERROR : " + ex.Message;
            }
            return(res);
        }
示例#5
0
        /// <summary>
        /// Generates and sends a report and fill the message body
        /// depending on the notification mode chosen
        /// </summary>
        public void SendReport(NotificationMode notificationMode, string surveyTitle, string emailFrom, string emailTo, string emailSubject)
        {
            IEmailing       emailing = EmailingFactory.Create();
            EmailingMessage mail     = new EmailingMessage();

            mail.FromEmail = emailFrom;
            if ((notificationMode == NotificationMode.EntryReport) || (notificationMode == NotificationMode.OnlyAnswersReport))
            {
                mail.Body = this.GenerateTextReport(notificationMode == NotificationMode.OnlyAnswersReport);
            }
            else
            {
                mail.Body = ResourceManager.GetString("ShortNotificationMessage");
            }
            mail.Subject = (emailSubject == null) ? string.Format(ResourceManager.GetString("NotificationSubject"), surveyTitle) : emailSubject;
            mail.ToEmail = emailTo;
            emailing.SendEmail(mail);
        }
        // Notify System Operators about an exception
        public static void NotifySystemOps(Exception exc)
        {
            //    // Include code for notifying IT system operators

            IEmailing       emailing = EmailingFactory.Create();
            EmailingMessage mail     = new EmailingMessage();

            mail.FromEmail = EmailConfig.NSurveySMTPServerAuthUserName;

            mail.Body = "Survey Project Warning Message: Global Page Error details."
                        + "<br /><br />Inner Exception Type: " + exc.InnerException.GetType().ToString()
                        + "<br /><br />Inner Exception: " + exc.InnerException.Message
                        + "<br /><br />Inner Source: " + exc.InnerException.Source
                        + "<br /><br />Inner Stack Trace: " + exc.InnerException.StackTrace
                        + "<br /><br />Exception Type: " + exc.GetType().ToString()
                        + "<br /><br />Exception: " + exc.Message
                        + "<br /><br />Stack Trace: " + exc.StackTrace;

            mail.Subject = "Survey Project Warning Message: Global Page Error";
            mail.ToEmail = EmailConfig.NSurveySMTPServerAuthUserName;
            emailing.SendEmail(mail);
        }
示例#7
0
        /// <summary>
        /// description: ......
        /// </summary>
        /// <param name="sessionId">description .....</param>
        /// <param name="surveyId">description ....</param>
        /// <param name="anonymousEntries">description ..</param>
        /// <param name="mailingEmails">description .......</param>
        /// <param name="message">description ......</param>
        public void MailIt(string sessionId, int surveyId, bool anonymousEntries, string mailingEmails, EmailingMessage message)
        {
            IEmailing mailService   = EmailingFactory.Create();
            string    guid          = null,
                      taggedMessage = message.Body,
                      email;

            string[] mailingList = mailingEmails.Split(',');

            SyncDataStore.SetRecords(sessionId + ":" + "Progress", 0);
            SyncDataStore.SetRecords(sessionId + ":" + "FailedEmails", 0);

            int failedEmails = 0;

            // Send the invitation email to the list
            for (int i = 0; i < mailingList.Length; i++)
            {
                email = mailingList[i].Trim();
                guid  = null;
                try
                {
                    guid            = new Voter().GenerateVoterInvitationUId(surveyId, email, anonymousEntries);
                    message.Body    = message.Body.Replace("[--invitationid-]", guid);
                    message.ToEmail = email;
                    mailService.SendEmail(message);
                    message.Body = taggedMessage;
                }
                catch (Exception ex)
                {
                    try
                    {
                        if (guid != null)
                        {
                            // rollback db state if an email has been saved
                            new Voter().DeleteVoterInvitation(surveyId, email);
                        }

                        InvitationLogData invitationLogs = new InvitationLogData();
                        InvitationLogData.InvitationLogsRow invitationLog = invitationLogs.InvitationLogs.NewInvitationLogsRow();
                        invitationLog.ExceptionMessage = (ex.InnerException != null && ex.InnerException.InnerException != null) ?
                                                         ex.InnerException.InnerException.Message : ex.Message.ToString();
                        invitationLog.ExceptionType = (ex.InnerException != null && ex.InnerException.InnerException != null) ?
                                                      ex.InnerException.InnerException.GetType().ToString() : ex.GetType().ToString();
                        invitationLog.SurveyId  = surveyId;
                        invitationLog.Email     = email;
                        invitationLog.ErrorDate = DateTime.Now;
                        invitationLogs.InvitationLogs.AddInvitationLogsRow(invitationLog);

                        // Log error in the database
                        new Voter().LogInvitationError(invitationLogs);
                        failedEmails++;
                    }
                    catch (Exception e)
                    {
                        SyncDataStore.SetRecords(sessionId + ":" + "Error", e);
                    }
                }

                SyncDataStore.UpdateRecords(sessionId + ":" + "Progress", (i * 100) / mailingList.Length);
                SyncDataStore.UpdateRecords(sessionId + ":" + "FailedEmails", failedEmails);
            }
        }
示例#8
0
 /// <summary>
 /// description: Begins an asynchronous call
 /// </summary>
 /// <param name="sessionId">description .....</param>
 /// <param name="surveyId">description ....</param>
 /// <param name="anonymousEntries">description ..</param>
 /// <param name="mailingEmails">description .... ...</param>
 /// <param name="message">description ......</param>
 /// <param name="callback">description .. .....</param>
 /// <param name="state">description ..... .</param>
 /// <returns>Description returned value.</returns>
 public System.IAsyncResult BeginMailIt(string sessionId, int surveyId, bool anonymousEntries, string mailingEmails, EmailingMessage message, System.AsyncCallback callback, object state)
 {
     return(this.mailItDelegate.BeginInvoke(sessionId, surveyId, anonymousEntries, mailingEmails, message, callback, state));
 }