public static async void SendEmail(this EmailModel email) { try { var mail = email.GetMailMessage(); var server = GetMailServer(email); await server.SendMailAsync(mail); WindowsEventLog.WriteInfoLog($"Notify emails successfully sent to {string.Join(" - ", mail.To)}"); } catch (Exception exp) { WindowsEventLog.WriteErrorLog($"Exception in Sending Email: {exp.Message}"); } }
public static string ReadFileSafely(string path) { try { if (!File.Exists(path)) { return(null); } return(File.ReadAllText(path, Encoding.UTF8)); } catch (Exception e) { WindowsEventLog.WriteErrorLog("Exception in FileManager: " + e.Message); } return(null); }
public static bool WriteFileSafely(string path, string data) { try { var pathDir = Path.GetDirectoryName(path); if (!Directory.Exists(pathDir)) { Directory.CreateDirectory(pathDir); } //Open the File File.WriteAllText(path, data, Encoding.UTF8); return(true); } catch (Exception e) { WindowsEventLog.WriteErrorLog("Exception in FileManager: " + e.Message); } return(false); }