private void UpdateDNS() { try { string updateResult = ""; string emailError = ""; DuckDnsResponse response = null; notifyIcon.Icon = icoTrayC; bool update = ddns.Update(out updateResult, out response); lblInfo.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $": DuckDns Update: " + (update ? "OK" : "FAILED"); EmailWrap(update, updateResult, out emailError, response); if (!update) { Show(); } } finally { notifyIcon.Icon = icoTray; } }
private void EmailWrap(bool isUpdate, string updateResult, out string emailError, DuckDnsResponse response) { emailError = ""; int maxEmail = -1; int.TryParse(tbMaxEmail.Text, out maxEmail); var emailInfo = ""; if (isUpdate && response != null && response.IsUpdated) { var isSent = Email("DuckDNS updater - IP Updated", updateResult, out emailError); if (!isSent) { emailInfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $": email sent error: {emailError}"; } else { emailInfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $": email sent: IP Updated - {response.Ip}"; } } if (!isUpdate) { if (maxEmail <= EmailSentNo && maxEmail != -1) { emailInfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $": Max ({EmailSentNo}) emails reached"; } else { var isSent = Email("DuckDNS updater - Error", updateResult, out emailError); EmailSentNo++; emailInfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $": email sent ({EmailSentNo}/{maxEmail})"; if (!isSent) { emailInfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $": email sent error: {emailError}"; } } } lblInfo2.Text = emailInfo; }