예제 #1
0
        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}");
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }