コード例 #1
0
ファイル: EmailCheck.cs プロジェクト: theresadower/graywulf
        public override void Execute(PageBase page)
        {
            var smtpclient = new SmtpClient();

            page.Response.Output.WriteLine(
                "Sending e-mail message to {0}",
                EmailAddress);

            page.Response.Output.WriteLine("Delivery method: {0}", smtpclient.DeliveryMethod);
            page.Response.Output.WriteLine("Server: {0}:{1}", smtpclient.Host, smtpclient.Port);

            var subject = String.Format("{0} test message from {1}", page.Domain.ShortTitle, Environment.MachineName);
            var body    = "Test message, please ignore.";

            var msg = EmailTemplateUtility.CreateMessage(
                page.Domain.Email, page.Domain.ShortTitle,
                EmailAddress, EmailAddress,
                subject, body);

            EmailTemplateUtility.SendMessage(msg);

            page.Response.Output.WriteLine("E-mail message sent.");
        }
コード例 #2
0
        protected void Ok_Click(object sender, EventArgs e)
        {
            string    templatefile;
            Exception ex      = null;
            long      eventid = 0;

            if (mode == Mode.Error && Session[Constants.SessionException] != null)
            {
                ex      = (Exception)Session[Constants.SessionException];
                eventid = (long)Session[Constants.SessionExceptionEventID];

                templatefile = "~/Templates/ErrorFeedbackEmail.xml";
            }
            else if (mode == Mode.JobError)
            {
                templatefile = "~/Templates/ErrorFeedbackEmail.xml";
            }
            else
            {
                templatefile = "~/Templates/FeedbackEmail.xml";
            }

            var    template = File.ReadAllText(MapPath(templatefile));
            string subject;
            string body;

            EmailTemplateUtility.LoadEmailTemplate(template, out subject, out body);

            EmailTemplateUtility.ReplaceEmailToken(ref subject, "[$ShortTitle]", Federation.ShortTitle);
            EmailTemplateUtility.ReplaceEmailToken(ref subject, "[$Subject]", Subject.Text);

            EmailTemplateUtility.ReplaceEmailToken(ref body, "[$ShortTitle]", Federation.ShortTitle);
            EmailTemplateUtility.ReplaceEmailToken(ref body, "[$Name]", Name.Text);
            EmailTemplateUtility.ReplaceEmailToken(ref body, "[$Email]", Email.Text);
            EmailTemplateUtility.ReplaceEmailToken(ref body, "[$Subject]", Subject.Text);
            EmailTemplateUtility.ReplaceEmailToken(ref body, "[$Comments]", Comments.Text);

            if (mode == Mode.Error && Session[Constants.SessionException] != null)
            {
                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$ErrorMessage]", ex.Message);
                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$JobGUID]", "-");
                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$EventID]", eventid.ToString());
            }
            else if (mode == Mode.JobError)
            {
                var job = new JobInstance(RegistryContext);
                job.Guid = jobGuid;
                job.Load();

                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$ErrorMessage]", job.ExceptionMessage);
                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$JobGUID]", job.Guid.ToString());
                EmailTemplateUtility.ReplaceEmailToken(ref body, "[$EventID]", "-");
            }

            var msg = EmailTemplateUtility.CreateMessage(
                Federation.Email, Federation.ShortTitle,
                Federation.Email, Federation.ShortTitle,
                subject, body);

            // Append stack trace
            if (mode == Mode.Error && Session[Constants.SessionException] != null)
            {
                System.Net.Mail.Attachment att;

                using (var mem = new MemoryStream(Encoding.UTF8.GetBytes(new HttpUnhandledException(ex.Message, ex).GetHtmlErrorMessage())))
                {
                    att = new System.Net.Mail.Attachment(mem, "error.html");

                    msg.Attachments.Add(att);
                    EmailTemplateUtility.SendMessage(msg);
                }
            }
            else
            {
                EmailTemplateUtility.SendMessage(msg);
            }

            FeedbackForm.Visible = false;
            SuccessForm.Visible  = true;
        }