Esempio n. 1
0
        public override void InnerRun(Dictionary <string, object> vars, Dictionary <string, object> outputVars, Dictionary <string, object> InvertedInputVars, Message message)
        {
            // init
            COREobject core = COREobject.i;

            string         msg   = vars.ContainsKey("Message") ? (string)vars["Message"] : string.Empty;
            OmniusLogLevel level = vars.ContainsKey("Level") ? (OmniusLogLevel)vars["Level"] : OmniusLogLevel.Info;

            OmniusLog.Log(msg, level, OmniusLogSource.User, core.Application, core.User);
        }
Esempio n. 2
0
 public void BCC(Dictionary <string, string> addressList)
 {
     mail.Bcc.Clear();
     foreach (KeyValuePair <string, string> addr in addressList.Where(pair => pair.Key != ""))
     {
         if (new EmailAddressAttribute().IsValid(addr.Key))
         {
             mail.Bcc.Add(new MailAddress(addr.Key, addr.Value));
         }
         else
         {
             OmniusLog.Log($"User passed invalid email address '{addr.Key}'.", OmniusLogLevel.Warning, OmniusLogSource.Hermes);
         }
     }
 }
Esempio n. 3
0
        public bool SendMail(Application application = null, bool disposeClient = true)
        {
            if (mail.To.Count + mail.Bcc.Count == 0)
            {
                return(true);
            }
            bool   result;
            string smtpError = "";

            if (attachmentList.Count() > 0)
            {
                mail.Attachments.Clear();
                for (int i = 0; i < attachmentList.Count(); i++)
                {
                    Attachment att;
                    if (!attachmentList[i].GetType().Equals(typeof(JValue)))
                    {
                        FileMetadata fileInfo = e.FileMetadataRecords.Find((int)attachmentList[i]["Key"]);
                        try {
                            byte[] data        = fileInfo.CachedCopy.Blob;
                            Stream fileContent = new MemoryStream(data);

                            att = new Attachment(fileContent, fileInfo.Filename);
                        }
                        catch (NullReferenceException ex)
                        {
                            OmniusException.Log($"Odeslání e-mailu se nezdařilo - příloha <b>{attachmentList[i]["Value"].ToString()}</b> nebyla nalezena", OmniusLogSource.Hermes, ex, application);
                            return(false);
                        }
                    }
                    else
                    {
                        string path = attachmentList[i].ToString();
                        att = new Attachment(path);
                    }
                    mail.Attachments.Add(att);
                }
            }

            try {
                client.Send(mail);
                result = true;
            }
            catch (Exception e)
            {
                result    = false;
                smtpError = e.Message;
            }

            // Uložíme do logu
            EmailLog log = new EmailLog();

            log.Content    = HermesUtils.SerializeMailMessage(mail, Formatting.Indented);
            log.DateSend   = DateTime.UtcNow;
            log.Status     = result ? EmailSendStatus.success : EmailSendStatus.failed;
            log.SMTP_Error = smtpError;

            e.EmailLogItems.Add(log);
            e.SaveChanges();

            OmniusLog.Log($"Odeslání e-mailu \"{mail.Subject}\" (<a href=\"/Hermes/Log/Detail/{log.Id}\" title=\"Detail e-mailu\">detail e-mailu</a>)", (result ? OmniusLogLevel.Info : OmniusLogLevel.Error), OmniusLogSource.Hermes, application);

            if (disposeClient)
            {
                client.Dispose();
            }

            return(result);
        }
Esempio n. 4
0
 public static void Log(COREobject core, string Message, OmniusLogLevel Level = OmniusLogLevel.Info)
 {
     OmniusLog.Log(Message, Level, OmniusLogSource.User, core.Application, core.User);
 }