public void SendReport(CrashReportDetails crashReport) { // Convert ReportItems to EmailBody string emailBody = ""; using (System.IO.StringWriter stringWriter = new System.IO.StringWriter()) { System.Xml.Serialization.XmlSerializerNamespaces ns = new System.Xml.Serialization.XmlSerializerNamespaces(); ns.Add("", ""); System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(crashReport.GetType(), crashReport.GetItemTypes()); x.Serialize(stringWriter, crashReport, ns); emailBody = stringWriter.ToString(); } using (MailMessage msg = new MailMessage()) { msg.From = new MailAddress(EmailFromAddress); foreach (string s in EmailToAddress.Split(";".ToCharArray())) { msg.To.Add(s); } if (String.IsNullOrEmpty(EmailSubject)) { msg.Subject = Application.ProductName + " - Error Report"; } else { msg.Subject = EmailSubject; } msg.Body = emailBody; SmtpClient smtp = null; if (String.IsNullOrEmpty(EmailHost)) { smtp = new SmtpClient(); } else { if (EmailPort == 0) { smtp = new SmtpClient(EmailHost); } else { smtp = new SmtpClient(EmailHost, EmailPort); } } if (String.IsNullOrEmpty(EmailUsername) && String.IsNullOrEmpty(EmailPassword)) { smtp.UseDefaultCredentials = true; } else { smtp.Credentials = new System.Net.NetworkCredential(EmailUsername, EmailPassword); } smtp.EnableSsl = EmailSSL; smtp.Send(msg); } }
void SendTraceEmail(string message, string subject) { lock (_bundledSources) { MailMessage msg = new MailMessage(); msg.From = new MailAddress(EmailFromAddress); foreach (string s in EmailToAddress.Split(";".ToCharArray())) { msg.To.Add(s); } if (String.IsNullOrEmpty(subject)) { msg.Subject = EmailFormatSubject; } else { msg.Subject = subject; } msg.Body = message; _smtpClient = null; if (String.IsNullOrEmpty(EmailHost)) { _smtpClient = new SmtpClient(); // Use <system.net><mailSettings> } else { if (String.IsNullOrEmpty(EmailPort)) { _smtpClient = new SmtpClient(EmailHost); } else { _smtpClient = new SmtpClient(EmailHost, Int32.Parse(EmailPort)); } if (String.IsNullOrEmpty(EmailUsername) && String.IsNullOrEmpty(EmailPassword)) { _smtpClient.UseDefaultCredentials = true; } else { _smtpClient.Credentials = new System.Net.NetworkCredential(EmailUsername, EmailPassword); } } if (!String.IsNullOrEmpty(EmailSsl)) { _smtpClient.EnableSsl = true; // Only .NET 4.0 and newer support EnableSsl in <system.net><mailSettings> } _smtpClient.SendCompleted += smtp_SendCompleted; _smtpClient.SendAsync(msg, msg); } }
public SnapshotDiffOptions(JToken args, int id) { if (args == null) { return; } Id = id; foreach (JProperty arg in args) { string key = arg.Name.Trim(); string value = arg.Value.ToString().Trim(); bool found = false; foreach (PropertyInfo prop in GetProps()) { if (prop.Name.Equals(key, StringComparison.OrdinalIgnoreCase)) { found = true; if (prop.PropertyType.IsEnum) { prop.SetValue(this, Enum.Parse(prop.PropertyType, value, true)); } else { prop.SetValue(this, Convert.ChangeType(value, prop.PropertyType, CultureInfo.InvariantCulture)); } break; } } if (!found) { throw new ArgumentException("Unrecognized argument " + key); } } if (EmailHost == "youremailserver") { throw new ArgumentException("Invalid email server " + EmailHost); } EmailFromAddresses = new MailboxAddress[] { new MailboxAddress(EmailFromName, EmailFromAddress) }; EmailToAddresses = EmailToAddress.Split(',').Select(e => new MailboxAddress(e)).ToArray(); string[] rectPieces = Rect.Split(','); try { Rectangle srcRect = new Rectangle(int.Parse(rectPieces[0]), int.Parse(rectPieces[1]), int.Parse(rectPieces[2]), int.Parse(rectPieces[3])); if (srcRect.X >= BrowserWidth) { throw new ArgumentException("Rect is out of bounds from browser width"); } if (srcRect.Y >= BrowserHeight) { throw new ArgumentException("Rect is out of bounds from browser height"); } if (srcRect.Width <= 0 || srcRect.X + srcRect.Width > BrowserWidth) { srcRect.Width = BrowserWidth - srcRect.X; } if (srcRect.Height <= 0 || srcRect.Y + srcRect.Height > BrowserHeight) { srcRect.Height = BrowserHeight - srcRect.Y; } SourceRect = srcRect; } catch (Exception ex) { throw new ArgumentException("Invalid Rect: " + Rect + ", " + ex); } }