public static bool SendEmail(EmailSettings emailSettings, string subject, string body) { try { var emailPassword = SecurityHelpers.DecodeSecret(emailSettings.EmailPassword); var client = new SmtpClient(emailSettings.EmailServerAddress, emailSettings.EmailPort) { Credentials = new NetworkCredential(emailSettings.EmailUser, emailPassword), EnableSsl = emailSettings.EmailUseSSL }; //Create the email var mailMessage = new MailMessage(emailSettings.EmailUser, emailSettings.EmailTo, subject, body); //Try to attach the log if specified var logFile = Path.Combine(Environment.CurrentDirectory, "logs", "logfile.txt"); if (File.Exists(logFile)) mailMessage.Attachments.Add(new Attachment(logFile)); else { log.Warn("Unable to find log file to attach: " + logFile); } client.Send(mailMessage); return true; }catch(Exception e) { log.ErrorException("Could not send email. " + subject, e); return false; } }
public BackupSettings() { SevenZipExecutablePath = @"7za.exe"; CompressionLevel = 9; EncryptHeaders = false; LocalBackupFolder = @"D:\Bak\"; BackupJobs = new List<BackupJob> { new BackupJob { BackupName = "Logs", BackupLocations = new List<string> {@"C:\temp\logs"}, MaxFullBackupAgeDays = 20, NumberIncremental = 3, }, new BackupJob { BackupName = "VIZ", BackupLocations = new List<string> {@"C:\temp\viz"}, MaxFullBackupAgeDays = 20, NumberIncremental = 3, } }; EmailSettings = new EmailSettings {EmailServerAddress = "smtp.gmail.com", EmailPort = 587, EmailTo = "*****@*****.**", EmailUser = "******"}; FTPSettings = new FTPSettings { FTPServerAddress = "ftp.com", FTPPort = 21, FTPUser = "******", FTPVerifySizes = true}; }