/// <summary>Emails the report contained in the Attached MemoryStream to the specified user</summary> /// <param name="userId">The requestor/recipient of the report</param> /// <param name="attachmentName">The name of the Email attachment</param> /// <param name="report">MemoryStream object containing the report data</param> /// <param name="startTime">The DateTime that the report was requested</param> /// <param name="endTime">The DateTime that the report was completed</param> public void EmailReport(string userId, string attachmentName, MemoryStream report, DateTime startTime, DateTime endTime) { try { TimeSpan span = endTime.Subtract(startTime); string elapsedTime = span.Minutes + " minute" + ((span.Minutes != 1) ? "s, " : ", ") + span.Seconds + " second" + ((span.Seconds != 1) ? "s" : "") + "."; StringBuilder body = new StringBuilder(); body.Append("Report requested on: "); body.AppendLine(startTime.ToShortDateString() + " at " + startTime.ToShortTimeString()); //body.Append("<br/>Elapsed time: "); //body.AppendLine(elapsedTime); Message mail = new Message(WebCommon.SmtpAddress); mail.AddRecipient(Security.GetUserEmailFromId(userId)); mail.Subject = "Titan 360 Commission Report"; mail.From = ConfigurationManager.AppSettings["mailingName"].ToString(); mail.Body = body.ToString(); mail.AddAttachmentFromStream(report, attachmentName, "application/zip"); WebCommon.WriteDebugMessage(string.Format("Emailing report at {0} to {1}, file size: {2}.", (startTime.ToShortDateString() + " at " + startTime.ToShortTimeString()), userId, report.Length)); mail.SendEmail(); } catch (Exception ex) { WebCommon.LogExceptionInfo(ex); EmailReportErrorMessage(userId, startTime); } }