Abstractions.Windows.Networking.email C# (CSharp) Method

email() public static method

does send a mail including the last 60 system-Event and application-Event lines plus the last 175 pgina logfile lines
public static email ( string mailAddress, string smtpAddress, string username, string password, string subject, string body, bool ssl ) : System.Boolean
mailAddress string
smtpAddress string
username string
password string
subject string
body string
ssl bool
return System.Boolean
        public static Boolean email(string[] mailAddress, string[] smtpAddress, string username, string password, string subject, string body, bool ssl)
        {
            Boolean ret = false;

            #region input checks
            if (mailAddress.Length == 0)
            {
                LibraryLogging.Error("can't send email: mailAddress.Length == 0");
                return false;
            }
            else
            {
                bool atleastonemail = false;
                foreach (string str in mailAddress)
                {
                    if (!String.IsNullOrEmpty(str))
                    {
                        atleastonemail = true;
                        break;
                    }
                }
                if (!atleastonemail)
                {
                    LibraryLogging.Error("can't send email: mailAddress array is empty");
                    return false;
                }
            }
            if (smtpAddress.Length == 0)
            {
                LibraryLogging.Error("can't send email: smtpAddress.Length == 0");
                return false;
            }
            else
            {
                bool atleastoneserver = false;
                foreach (string str in smtpAddress)
                {
                    if (!String.IsNullOrEmpty(str))
                    {
                        atleastoneserver = true;
                        break;
                    }
                }
                if (!atleastoneserver)
                {
                    LibraryLogging.Error("can't send email: smtpAddress array is empty");
                    return false;
                }
            }
            if (String.IsNullOrEmpty(subject))
            {
                LibraryLogging.Error("can't send email: subject is empty");
            }
            #endregion

            try
            {
                using (EventLog systemLog = new EventLog("System"))
                {
                    body += "\n\n====================Eventlog System====================\n";
                    for (int x = systemLog.Entries.Count - 60; x < systemLog.Entries.Count; x++)
                    {
                        body += String.Format("{0:yyyy-MM-dd HH:mm:ss} {1} {2} {3}\n", systemLog.Entries[x].TimeGenerated, systemLog.Entries[x].EntryType, (UInt16)systemLog.Entries[x].InstanceId, systemLog.Entries[x].Message);
                    }
                }
                using (EventLog application = new EventLog("Application"))
                {
                    body += "\n\n====================Eventlog Application===============\n";
                    for (int x = application.Entries.Count - 60; x < application.Entries.Count; x++)
                    {
                        body += String.Format("{0:yyyy-MM-dd HH:mm:ss} {1} {2} {3}\n", application.Entries[x].TimeGenerated, application.Entries[x].EntryType, (UInt16)application.Entries[x].InstanceId, application.Entries[x].Message);
                    }
                }
            }
            catch { }

            ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

            for (uint x = 0; x < smtpAddress.Length; x++)
            {
                string smtp = smtpAddress[x].Split(new char[] { ':' }).First();
                int port = 465;
                if (String.Compare(smtp, smtpAddress[x].Split(new char[] { ':' }).Last()) != 0)
                {
                    try
                    {
                        port = Convert.ToInt32(smtpAddress[x].Split(new char[] { ':' }).Last());
                    }
                    catch (Exception ex)
                    {
                        LibraryLogging.Warn("unable to retrieve smtp port from {0} Error:{1}", smtpAddress[x], ex.Message);
                        continue;
                    }
                }
                using (SmtpClient client = new SmtpClient(smtp, port))
                {
                    client.EnableSsl = ssl;
                    client.Timeout = Convert.ToInt32(new TimeSpan(0, 0, 30).TotalMilliseconds);
                    if (!String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password))
                    {
                        client.Credentials = new NetworkCredential(username, password);
                    }

                    for (uint y = 0; y < mailAddress.Length; y++)
                    {
                        if (mailAddress[y] == null)
                            continue;
                        try
                        {
                            // get the logfile
                            string logfile = null;
                            logfile = LogManager.GetRepository().GetAppenders().OfType<FileAppender>().Where(fa => fa.Name == "bigfile").Single().File;
                            if (!String.IsNullOrEmpty(logfile))
                            {
                                using (StreamReader log = new StreamReader(logfile, true))
                                {
                                    // read the last 50kbytes of the log
                                    if (log.BaseStream.Length > 50 * 1024) //50kbytes
                                        log.BaseStream.Seek(50 * 1024 * -1, SeekOrigin.End);

                                    string[] lastlines = log.ReadToEnd().Split('\n');
                                    int line_count = 0;
                                    if (lastlines.Length > 175)
                                        line_count = lastlines.Length - 176;
                                    body += "\n\n====================Pgina log==========================\n";
                                    for (; line_count < lastlines.Length; line_count++)
                                    {
                                        body += lastlines[line_count] + '\n';
                                    }
                                }
                            }

                            using (MailMessage message = new MailMessage(mailAddress[y], mailAddress[y], subject, body))
                            {
                                client.Send(message);
                            }
                            mailAddress[y] = null;
                        }
                        catch (Exception ex)
                        {
                            LibraryLogging.Warn("Failed to send message \"{0}\" to:{1} port:{2} Error:{3}", subject, smtp, port, ex.Message);
                        }
                    }
                }

                if (mailAddress.All(k => string.IsNullOrEmpty(k)))
                {
                    ret = true;
                    break;
                }
            }

            return ret;
        }