コード例 #1
0
ファイル: SmtpTraceListener.cs プロジェクト: avs009/gsf
        public override void Write(string message)
        {
            StringBuilder messageBuilder = new StringBuilder();

            // Appends standard information to the bottom of the message.
            messageBuilder.Append(message);
            messageBuilder.Append(Environment.NewLine + Environment.NewLine);
            messageBuilder.Append("This trace message was sent from the machine ");
            messageBuilder.Append(System.Net.Dns.GetHostName());
            messageBuilder.Append(" (");
            messageBuilder.Append(Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString());
            messageBuilder.Append(") at ");
            messageBuilder.Append(DateTime.Now);

            Mail mailMessage = new Mail();
            mailMessage.From = m_sender;
            mailMessage.Recipients = m_recipient;
            mailMessage.Subject = "Trace message for " + System.AppDomain.CurrentDomain.FriendlyName;
            mailMessage.Body = messageBuilder.ToString();
            mailMessage.Send();
        }
コード例 #2
0
ファイル: EmailNotifier.cs プロジェクト: avs009/gsf
        private void SendEmail(string subject, string message, string details)
        {
            if (string.IsNullOrEmpty(m_emailRecipients))
                throw new ArgumentNullException("EmailRecipients");

            Mail briefMessage = new Mail(m_emailSender, m_emailSender, m_emailServer);
            Mail detailedMessage = new Mail(m_emailSender, m_emailSender, m_emailServer);

            briefMessage.Subject = subject;
            detailedMessage.Subject = subject;
            detailedMessage.Body = message + "\r\n\r\n" + details;
            foreach (string recipient in m_emailRecipients.Replace(" ", "").Split(';', ','))
            {
                string[] addressParts = recipient.Split(':');
                if (addressParts.Length > 1)
                {
                    if (string.Compare(addressParts[1], "sms", true) == 0)
                    {
                        // A brief message is to be sent.
                        briefMessage.ToRecipients = addressParts[0];
                        briefMessage.Send();
                    }
                }
                else
                {
                    // A detailed message is to be sent.
                    detailedMessage.ToRecipients = recipient;
                    detailedMessage.Send();
                }
            }
        }
コード例 #3
0
ファイル: ErrorLogger.cs プロジェクト: avs009/gsf
 /// <summary>
 /// Logs encountered <see cref="Exception"/> to an e-mail message.
 /// </summary>
 /// <param name="exception"><see cref="Exception"/> that was encountered.</param>
 protected virtual void ExceptionToEmail(Exception exception)
 {
     // Log if enabled.
     if (m_logToEmail && !string.IsNullOrEmpty(m_contactEmail) && !m_suppressInteractiveLogging)
     {
         m_logToEmailOK = false;
         Mail email = new Mail(m_contactEmail, m_contactEmail);
         email.Subject = string.Format("Exception in {0} at {1}", ApplicationName, DateTime.Now.ToString());
         email.Body = GetExceptionInfo(exception, m_logUserInfo);
         email.Attachments = GetScreenshotFileName();
         email.SmtpServer = m_smtpServer;
         email.Send();
         m_logToEmailOK = true;
     }
 }
コード例 #4
0
ファイル: Mail.cs プロジェクト: avs009/gsf
 /// <summary>
 /// Sends a <see cref="Mail"/> message.
 /// </summary>
 /// <param name="from">The e-mail address of the <see cref="Mail"/> message sender.</param>
 /// <param name="toRecipients">A comma-separated or semicolon-seperated e-mail address list of the <see cref="Mail"/> message recipients.</param>
 /// <param name="ccRecipients">A comma-separated or semicolon-seperated e-mail address list of the <see cref="Mail"/> message carbon copy (CC) recipients.</param>
 /// <param name="bccRecipients">A comma-separated or semicolon-seperated e-mail address list of the <see cref="Mail"/> message blank carbon copy (BCC) recipients.</param>
 /// <param name="subject">The subject of the <see cref="Mail"/> message.</param>
 /// <param name="body">The body of the <see cref="Mail"/> message.</param>
 /// <param name="isBodyHtml">true if the <see cref="Mail"/> message body is to be formated as HTML; otherwise false.</param>
 /// <param name="attachments">A comma-separated or semicolon-seperated list of file names to be attached to the <see cref="Mail"/> message.</param>
 /// <param name="smtpServer">The name or IP address of the SMTP server to be used for sending the <see cref="Mail"/> message.</param>
 public static void Send(string from, string toRecipients, string ccRecipients, string bccRecipients, string subject, string body, bool isBodyHtml, string attachments, string smtpServer)
 {
     using (Mail email = new Mail(from, toRecipients, smtpServer))
     {
         email.CcRecipients = ccRecipients;
         email.BccRecipients = bccRecipients;
         email.Subject = subject;
         email.Body = body;
         email.IsBodyHtml = isBodyHtml;
         email.Attachments = attachments;
         email.Send();
     }
 }
コード例 #5
0
ファイル: ErrorLogger.cs プロジェクト: avs009/gsf
        /// <summary>
        /// Logs encountered exception to an email message.
        /// </summary>
        /// <param name="exception">Exception that was encountered.</param>
        protected virtual void ExceptionToEmail(Exception exception)
        {
            if (!m_logToEmail || string.IsNullOrEmpty(m_contactEmail)) return;

            m_logToEmailOK = false;
            Mail email = new Mail();
            email.From = string.Format("{0}@tva.gov", Environment.MachineName);
            email.Recipients = m_contactEmail;
            email.Subject = string.Format("Exception in {0} at {1}", ApplicationName, DateTime.Now.ToString());
            email.Body = GetExceptionInfo(exception);
            email.Attachments = GetScreenshotFileName();
            email.SmtpServer = m_smtpServer;
            email.Send();
            m_logToEmailOK = true;
        }
コード例 #6
0
ファイル: FlatlineTest.cs プロジェクト: avs009/gsf
        // Send an email address notifying the admin of a changes in the flatlined status of measurements.
        private void SendEmailNotification(IEnumerable<IMeasurement> measurements, bool flatlined)
        {
            Ticks now = DateTime.Now.Ticks;
            Mail message = new Mail("*****@*****.**", m_adminEmailAddress, m_smtpServer);
            StringBuilder body = new StringBuilder();

            body.AppendLine("Measurement Key, Value, Timestamp");

            foreach (IMeasurement measurement in measurements)
            {
                body.Append(measurement.Key);
                body.Append(", ");
                body.Append(measurement.AdjustedValue);
                body.Append(", ");
                body.Append(measurement.Timestamp);
                body.AppendLine();

                if (flatlined)
                    m_lastNotified[measurement.Key] = now;
                else
                    m_lastNotified.Remove(measurement.Key);
            }

            if (flatlined)
                message.Subject = "Flatlined measurements";
            else
                message.Subject = "No longer flatlined measurements";

            message.Body = body.ToString();
            message.Send();
            message.Dispose();
        }