コード例 #1
0
        public static void FtpDownloadComplete(User user, string messages)
        {
            // Get the message template and set the subject
            Email email = NotifyEngine.GetEmailTemplate("Admin.FtpDownloadComplete", user.PrimaryBrand);

            email.Subject = NotifyEngine.GetSubject("FTP download is complete", user.PrimaryBrand);

            // Add the user as a recipient
            email.Recipients.Add(user.Email);

            // Add message parameters
            email.AddBodyParameter("first-name", user.FirstName);

            // Add the FTP log to the message as an attachment
            email.AddAttachment(messages, "FtpLog.txt");

            // Send it
            NotifyEngine.SendMessage(email);
        }
コード例 #2
0
        private Email CreateDocumentEmail(string clientName, string organizationName, OrderDocument document)
        {
            if (document.Type == OrderDocumentType.Bill)
            {
                var billDocument     = document as BillDocument;
                var wasHideSignature = billDocument.HideSignature;
                billDocument.HideSignature = false;
                ReportInfo ri = billDocument.GetReportInfo();
                billDocument.HideSignature = wasHideSignature;

                EmailTemplate template = billDocument.GetEmailTemplate();
                Email         email    = new Email();
                email.Title    = string.Format("{0} {1}", template.Title, billDocument.Title);
                email.Text     = template.Text;
                email.HtmlText = template.TextHtml;
                foreach (var item in template.Attachments)
                {
                    email.AddInlinedAttachment(item.Key, item.Value.MIMEType, item.Value.FileName, item.Value.Base64Content);
                }

                email.Recipient         = new EmailContact(clientName, yvalidatedentryEmail.Text);
                email.Sender            = new EmailContact(organizationName, ParametersProvider.Instance.GetParameterValue("email_for_email_delivery"));
                email.Order             = document.Order.Id;
                email.OrderDocumentType = document.Type;
                using (MemoryStream stream = ReportExporter.ExportToMemoryStream(ri.GetReportUri(), ri.GetParametersString(), ri.ConnectionString, OutputPresentationType.PDF, true)) {
                    string billDate = billDocument.DocumentDate.HasValue ? "_" + billDocument.DocumentDate.Value.ToString("ddMMyyyy") : "";
                    email.AddAttachment($"Bill_{billDocument.Order.Id}{billDate}.pdf", stream);
                }
                return(email);
            }
            else
            {
                //для других документов не реализована отправка почты
                return(null);
            }
        }
コード例 #3
0
ファイル: ManualEmailSender.cs プロジェクト: RoAr80/Vodovoz
        public void ResendEmailWithErrorSendingStatus(DateTime date)
        {
            IEmailService service = EmailServiceSetting.GetEmailService();

            if (service == null)
            {
                return;
            }

            IList <StoredEmail> errorSendedEmails;

            using (var uowLocal = UnitOfWorkFactory.CreateWithoutRoot()) {
                StoredEmail unsendedEmailAlias        = null;
                StoredEmail alreadyResendedEmailAlias = null;

                var dateCriterion = Projections.SqlFunction(
                    new SQLFunctionTemplate(
                        NHibernateUtil.Date,
                        "Date(?1)"
                        ),
                    NHibernateUtil.Date,
                    Projections.Property <StoredEmail>(x => x.SendDate)
                    );
                ICriterion dateResctict   = Restrictions.Eq(dateCriterion, date.Date);
                ICriterion dateResctictGe = Restrictions.Ge(dateCriterion, date.Date);

                var resendedQuery = QueryOver.Of <StoredEmail>()
                                    .Where(Restrictions.EqProperty(Projections.Property <StoredEmail>(x => x.Order.Id), Projections.Property(() => unsendedEmailAlias.Order.Id)))
                                    .Where(x => x.State != StoredEmailStates.SendingError)
                                    .Where(dateResctictGe)
                                    .Select(Projections.Count(Projections.Id()));

                errorSendedEmails = uowLocal.Session.QueryOver <StoredEmail>(() => unsendedEmailAlias)
                                    .Where(x => x.State == StoredEmailStates.SendingError)
                                    .Where(dateResctict)
                                    .WithSubquery.WhereValue(0).Eq(resendedQuery)
                                    .List();

                foreach (var sendedEmail in errorSendedEmails)
                {
                    var billDocument = sendedEmail.Order.OrderDocuments.FirstOrDefault(y => y.Type == OrderDocumentType.Bill) as BillDocument;
                    if (billDocument == null)
                    {
                        continue;
                    }

                    billDocument.HideSignature = false;
                    ReportInfo ri = billDocument.GetReportInfo();

                    var   billTemplate = billDocument.GetEmailTemplate();
                    Email email        = new Email {
                        Title             = string.Format("{0} {1}", billTemplate.Title, billDocument.Title),
                        Text              = billTemplate.Text,
                        HtmlText          = billTemplate.TextHtml,
                        Recipient         = new EmailContact("", sendedEmail.RecipientAddress),
                        Sender            = new EmailContact("vodovoz-spb.ru", ParametersProvider.Instance.GetParameterValue("email_for_email_delivery")),
                        Order             = billDocument.Order.Id,
                        OrderDocumentType = OrderDocumentType.Bill
                    };
                    foreach (var item in billTemplate.Attachments)
                    {
                        email.AddInlinedAttachment(item.Key, item.Value.MIMEType, item.Value.FileName, item.Value.Base64Content);
                    }
                    using (MemoryStream stream = ReportExporter.ExportToMemoryStream(ri.GetReportUri(), ri.GetParametersString(), ri.ConnectionString, OutputPresentationType.PDF, true)) {
                        string billDate = billDocument.DocumentDate.HasValue ? "_" + billDocument.DocumentDate.Value.ToString("ddMMyyyy") : "";
                        email.AddAttachment($"Bill_{billDocument.Order.Id}{billDate}.pdf", stream);
                    }
                    email.AuthorId      = sendedEmail.Author.Id;
                    email.ManualSending = sendedEmail.ManualSending ?? false;

                    service.SendEmail(email);
                }
            }
        }