예제 #1
0
        private static bool LogErrorReport(Logging.DiagnosticData dump)
        {
            // note: normally 404s are not emailed to us, but if we have any processes that we need to ensure will send us an email on a 404 we can specify emailonfail=1 in the querystring
            if (!CheckIfErrorShouldBeLogged(dump))
            {
                return(false);
            }

            bool wasLogged = false;

            try {
                //Logging.dlog("LogErrorReport try logging");
                double secondsSinceLastReported = dump.SecondsSinceLastReport;
                var    isNewError = secondsSinceLastReported == 0 || secondsSinceLastReported > Util.GetSetting("ThrottleSameError", "60").ToInt(60);

                if (!isNewError)
                {
                    // assume already logged previously, so we want to display to the user that we have logged this error
                    wasLogged = true;
                }
                else
                {
                    wasLogged      = PostErrorReport(dump);
                    dump.WasLogged = wasLogged;
                }
                //Logging.dlog("LogErrorReport result: "+ wasLogged);
            } catch (Exception e) {
                //Logging.dlog("LogErrorReport problem [" + e.Message + "]");
                SendEMail.SimpleSendEmail("*****@*****.**", "LogErrorReport problem", e.Message);
            }
            return(wasLogged);
        }
예제 #2
0
        private void PrepBody()
        {
            if (this.IsTracked)
            {
                BodyHtml = SendEMail.AddGoogleCampaignTrackingCodes(BodyHtml, TrackingSource, TrackingCampaign);

                if (BodyHtml.IsNotBlank())
                {
                    BodyHtml += Environment.NewLine + "<img src='" + Web.BaseUrl + "track/" + trackingGuid + "' />";
                }
            }

            if (BodyHtml.IsNotBlank() && BodyPlain.IsNotBlank())
            {
                message.IsBodyHtml = true;
                message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(BodyPlain, null, "text/plain"));
                message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(BodyHtml, null, "text/html"));
            }
            else if (BodyHtml.IsNotBlank())
            {
                message.IsBodyHtml = true;
                message.Body       = BodyHtml;
            }
            else
            {
                message.IsBodyHtml = false;
                message.Body       = BodyPlain;
            }
        }
예제 #3
0
        /// <summary>
        /// Send an html email from the default from address.
        /// StripTags is run on html to get an alternative plain text version.
        /// If ok, return null
        /// </summary>
        /// <param name="to"></param>
        /// <param name="subject"></param>
        /// <param name="htmlBody"></param>
        /// <param name="attachments">files will full path, sep by ;</param>
        public static string SimpleSendHtmlEmail(string to, string subject, string htmlBody, string attachments)
        {
            string result = null;

            if (!String.IsNullOrEmpty(to))
            {
                var    envelope = new SendEMail();
                string rawbody  = htmlBody;
                string body     = "";
                if (!rawbody.Contains("<style"))
                {
                    string styles = "<style type='text/css'>";
                    styles += "p, ol li{margin:0;padding:0;font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#333333;}";
                    styles += "h2, h3, h4, h5, h6 {margin:0;padding:0;font-family:Arial, Helvetica, sans-serif;color:#1e3444;}";
                    styles += "h2 {font-size:14px;}";
                    styles += "h3 {font-size:13px;}";
                    styles += "h4 {font-size:12px;}";
                    styles += "h5 {font-size:15px;}";
                    styles += "h6 {font-size:11px;color:#666;}";
                    styles += "a {color:#0097d0;text-decoration:none;}";
                    styles += "table td {font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#333333;}";
                    styles += "</style>";
                    body    = styles;
                }
                // fix relative links from tinyMCE - may be able to remove this later
                if (Util.ServerIs() == "LVE" || Util.ServerIs() == "STG")
                {
                    // you must use assign to a new variable when using replace. else use Regex.Replace(string, searchText, replaceText)
                    body += rawbody.Replace("../../..", Web.BaseUrl);
                }
                else
                {
                    // it's DEV
                    //to = Util.GetNamedSetting("EmailToAddress"); // MN 20110511 this overrides all emails sent from DEV server, which can be annoying - uncomment this temporarily if desired
                    body += rawbody.Replace("../../../../", Web.BaseUrl);
                }
                if (!envelope.SendEmail(subject, body, Fmt.StripTags(body), "html", to, to, EmailFromAddress, EmailFromName, attachments))
                {
                    result = envelope.errorResult;
                }
            }
            else
            {
                throw new Exception("Send mail failed. Email 'to' address blank");
            }
            return(result);
        }
예제 #4
0
        /// <summary>
        /// Send the message. Returns true if successful or false if error sending email.
        /// Pass in true as the parameter if you wish it to throw an error instead of returning true/false.
        /// You can check the property ErrorResult to see what the error message was.
        /// </summary>
        /// <param name="throwErrors">true to throw an error</param>
        /// <returns>true if ok or false if error</returns>
        public bool Send(bool throwErrors)
        {
            bool result = true;

            Sql.LogOtherEventStart("sending mail");
            PrepAddresses();
            PrepBody();
            SmtpClient client = SendEMail.GetServerSmtpClient();

            try {
                Logging.dlog(message.Subject + " Email should be sending to : " + message.To);
                client.Send(message);
                if (Util.GetSettingBool("WriteEmailSendToDLogFile", false))
                {
                    Logging.dlog("Sent mail subject [" + message.Subject + "]: from [" + message.From + "] to [" + message.To + "] replyto [" + message.ReplyToList + "]");
                }
            } catch (Exception e) {
                string serverType = Util.ServerIs();
                string authuser   = ConfigurationManager.AppSettings.Get("EmailAuthUser" + serverType);
                string authpass   = ConfigurationManager.AppSettings.Get("EmailAuthPassword" + serverType);
                this.ErrorResult = "Error -em3: [" + message.Subject + "] usr[" + authuser + "] Host[" + client.Host + "] from[" + message.From + "]to[" + message.To + "] [" + e.Message + "]";
                result           = false;
                if (throwErrors)
                {
                    throw new BewebException(ErrorResult);
                }
            } finally {
                message.Dispose();
                Sql.LogOtherEventEnd("sending mail");

                if (UseMailLog)
                {
                    LogMessage();
                }
            }

            return(result);
        }
예제 #5
0
파일: Importer.cs 프로젝트: cmcd74/SavvyCMS
        /// <summary>
        /// Run the import. To tailor the import to handle a specific data format, create a derived class and override the various methods.
        /// </summary>
        public void ImportFilesInDropbox()
        {
            if (IsDropboxNotEmpty())
            {
                string dropboxFullPath          = Web.MapPath(IncomingPath);
                string dropboxProcessedFullPath = null;
                string dropboxRejectsFullPath   = null;
                if (!NoFilePermissionsMode)
                {
                    dropboxProcessedFullPath = Web.MapPath(ProcessedPath);
                    dropboxRejectsFullPath   = Web.MapPath(RejectsPath);
                }

                try {
                    Init(dropboxFullPath, dropboxProcessedFullPath, dropboxRejectsFullPath);

                    string[] files;
                    if (DirectoryFilter.IsNotBlank())
                    {
                        files = Directory.GetFiles(dropboxFullPath, DirectoryFilter);
                    }
                    else
                    {
                        files = Directory.GetFiles(dropboxFullPath);
                    }

                    foreach (var pathname in files)
                    {
                        string filename = pathname.RightFrom("\\");

                        this.fileName = filename;

                        if (!NoFilePermissionsMode || new Sql("select count(*) from DataImport where filename=", filename.SqlizeText()).FetchIntOrZero() == 0)
                        {
                            // process new file
                            var ok = ProcessFile(dropboxFullPath, filename);

                            bool useUniqueFiles = Util.GetSettingBool("ImporterUniqueFiles", true);
                            if (ok)
                            {
                                if (NoFilePermissionsMode)
                                {
                                    var log = new ActiveRecord("DataImport", "DataImportID");
                                    log["FileName"].ValueObject     = filename;
                                    log["DateImported"].ValueObject = DateTime.Now;
                                    log["ImportedBy"].ValueObject   = "Importer";
                                    log.Save();
                                }
                                else
                                {
                                    //bool useUniqueFiles = Util.GetSettingBool("ImporterUniqueFiles", true);
                                    string destfilename = filename;
                                    if (useUniqueFiles)
                                    {
                                        destfilename = FileSystem.GetUniqueFilename(dropboxFullPath + "\\", filename, 50, true);
                                    }

                                    if (Util.GetSettingBool("ImporterMoveFiles", true) && MoveImportedFiles)
                                    {
                                        bool allowOverwrite = !useUniqueFiles;
                                        FileSystem.Move(dropboxFullPath + "\\" + filename, dropboxProcessedFullPath + "\\" + destfilename, allowOverwrite);
                                    }
                                }

                                //Web.Response.Write("Imported file: " + filename + "<br>");
                                ImportSuccess(pathname);
                            }
                            else
                            {
                                if (ErrorAction == ErrorActions.ThrowError)
                                {
                                    throw new ProgrammingErrorException("Data Import Error: could not import file [" + filename + "]");
                                }
                                else if (ErrorAction == ErrorActions.EmailDeveloper)
                                {
                                    SendEMail.SimpleSendEmail(SendEMail.EmailAboutError, Util.GetSiteName() + " Import error", "Data Import Error: could not import file [" + filename + "]. Moved to Rejects folder.");
                                }
                                if (!NoFilePermissionsMode)
                                {
                                    if (!IsIgnoredIfError)
                                    {
                                        if (useUniqueFiles)
                                        {
                                            filename = FileSystem.GetUniqueFilename(dropboxRejectsFullPath + "\\", filename, 50, true);
                                        }
                                        bool allowOverwrite = !useUniqueFiles;

                                        try {
                                            FileSystem.Move(dropboxFullPath + "\\" + filename, dropboxRejectsFullPath + "\\" + filename, allowOverwrite);
                                        } catch (Exception e) {
                                            Web.Response.Write("NOK:file did not process ok. Also failed to move file: " + filename + " exception[" + e.Message + "]<br>");
                                        }
                                    }
                                }
                                Web.Response.Write("Could not import file: " + filename + "<br>");
                                //return; // just go on to the next file

                                ImportFailure(pathname);
                            }
                        }
                    }
                } catch (System.UnauthorizedAccessException accessException) {
                    throw new System.UnauthorizedAccessException("Drop folder problem: you need to grant the user ASPNET read/write/delete permissions over the folder '" + dropboxFullPath + "'.\n" + accessException.Message);
                }
            }
        }