public void SendSMTPMessage() { CrestronMailFunctions.SendMail(SMTPServer, Username, Password, SMTPFrom, To, NoCCAddresses, Subject, Body); }
public void SendGmailMessage() { CrestronMailFunctions.SendMail(GmailServerHost, GmailServerPort, SecureConnection, Username, Password, Username, To, NoCCAddresses, Subject, Body, NoAttachments, NoAttachmentFiles); }
//===================// METHODS //===================// //-------------------------------------// // Function | RequestLogs // Description | ... //-------------------------------------// public void RequestLogs(string _address, string _userName, string _password, bool forced, bool doSendEmail) { try { client = new HttpClient(); client.KeepAlive = false; client.TimeoutEnabled = true; client.Timeout = 6; client.UserName = _userName; client.Password = _password; request = new HttpClientRequest(); request.RequestType = RequestType.Get; request.Header.ContentType = "text/html"; request.Url.Parse("http://" + _address + "/admin/concierge/doplog?format=csv"); response = client.Dispatch(request); if (!response.ContentString.Contains("auth method")) { ErrorLog.Notice("[MOBOTIX] There was a problem fetching the logs from keypad {0}", deviceName); return; } string[] log = response.ContentString.Split('\n'); string[] entry = log[log.Length - 2].Split(','); string date = entry[0].Substring(1, entry[0].Length - 2); string timestamp = entry[1]; // Check Unix timestamp against current time Int32 currentTimeUnix = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; //ErrorLog.Notice("[MOBOTIX] UnixTime of Log {0}, UnixTime of Processor {1}", timestamp, currentTimeUnix); if (currentTimeUnix - Int32.Parse(timestamp) > 60) { // Log entry more than 60 seconds old, is probably not for this event if (lastEventTime != timestamp) { lastEventTime = timestamp; } ErrorLog.Notice("[MOBOTIX] Log timestamp exceeds age threshold, discarding event on keypad {0}", deviceName); return; } string action = ""; string user = ""; if (entry[2].Contains("Access denied")) { action = "Access Denied"; doSendEmail = false; // Per Client: Dont send emails on fail } else if (entry[2].Contains("Unknown User")) { action = "Access Granted"; user = entry[2].Substring(1, entry[2].Length - 2); } else { action = "Access Granted"; user = entry[2].Substring(1, (entry[2].IndexOf('(') - 2)); } // If user is defined, check user against userTable to see if a proper name exists if (user != "") { if (userTable != null) { foreach (KeyValuePair <string, string> dict in userTable) { if (user.Contains(dict.Key)) { user = dict.Value; break; } } } else { CrestronConsole.PrintLine("Error looking up Access UserID: UserTable is Null!"); } } // Remove Spaces from deviceName for file handling string deviceNameFileSafe = deviceName.Replace(" ", "_"); // Send if event is new event if (lastEventTime != timestamp || forced) { if (Log_Result_Callback != null) { Log_Result_Callback(date, timestamp, action, user); } lastEventTime = timestamp; if (doSendEmail && smtpConfigured) { string subject = string.Format("Mobotix - {0} code used at {1}", user, deviceName); string message = string.Format("Date: {0}\nActivity: {1}{2}", date, action, user != "" ? "\nDetails: " + user + " passcode opened " + deviceName : ""); string to = ""; for (int i = 0; i < mailRecipients.Count; i++) { if (i > 0) { to += "; "; } to += mailRecipients[i]; } CrestronMailFunctions.SendMailErrorCodes result; result = CrestronMailFunctions.SendMail( smtpServer, smtpPort, smtpUserName, smtpPassword, smtpFrom, to, "", subject, message, 1, "\\HTML\\mobo_" + deviceNameFileSafe + ".jpg"); ErrorLog.Notice("[MOBOTIX] SendMail result for keypad {0}: {1}", deviceName, result.ToString()); // If picture email fails, send text-only email if (result != CrestronMailFunctions.SendMailErrorCodes.SMTP_OK) { result = CrestronMailFunctions.SendMail( smtpServer, smtpPort, smtpUserName, smtpPassword, smtpFrom, to, "", subject, message + "\n(Picture not available)", 0, ""); ErrorLog.Notice("[MOBOTIX] Encountered an error sending picture email, falling back to text-only: {0}", result.ToString()); } } } } catch (Exception exc) { ErrorLog.Error("Error requesting access logs from address {0}!", _address); } }