Пример #1
0
        public void SendReportEmail(ContactNotify notify, ReportNotification notificationRecord, ReportRecord report)
        {
            try
            {
                var htmlBody = string.Empty;
                var textBody = string.Empty;

                if(File.Exists(AppVars.ReportTemplateHtml))
                    htmlBody = File.ReadAllText(AppVars.ReportTemplateHtml);
                if(File.Exists(AppVars.ReportTemplateText))
                    textBody = File.ReadAllText(AppVars.ReportTemplateText);

                MailMessage message = new MailMessage(new MailAddress(AppVars.ReportEmailAddress, "Analytical Research Laboratories"), new MailAddress(notify.Value.Trim(), notify.ContactName));
                MemoryStream stream = new MemoryStream(report.ReportData);
                Attachment attachment = new Attachment(stream, "Certificate of Analysis Report #" + notificationRecord.ReportId.ToString() + ".pdf");
                message.Subject = notificationRecord.SubjectLine; //report.Department.DepartmentName + " Certificate of Analysis Report";
                message.Body = textBody;
                message.IsBodyHtml = false;
                message.BodyEncoding = System.Text.Encoding.UTF8;

                if (!string.IsNullOrWhiteSpace(htmlBody))
                    message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html));

                message.Attachments.Add(attachment);

                SmtpClient smtp = new SmtpClient(AppVars.SmtpServer, AppVars.SmtpPort);
                smtp.EnableSsl = AppVars.SmtpServerUseSSL;
                smtp.Credentials = new System.Net.NetworkCredential(AppVars.SmtpAccount, AppVars.SmtpPassword);

                smtp.SendCompleted += SendReportMailCompletedCallback;
                notificationRecord.DisposeMessage = message;
                notificationRecord.DisposeStream = stream;
                smtp.SendAsync(message, notificationRecord);
            }
            catch
            {

                throw;
            }
        }
Пример #2
0
        public void ReportSendFaxAsync(ContactNotify notify, ReportNotification notificationRecord, ReportRecord report)
        {
            if (string.IsNullOrWhiteSpace(AppVars.FaxUserName) || string.IsNullOrWhiteSpace(AppVars.FaxPassword)) return;

            long result = 0;
            int retriesToPerform = 2;
            string pageHeader = "To: {To} From: {From} Pages: {TotalPages}";
            string pageSize = "Letter";
            string pageOrientation = "Portriat";
            bool isHighResolution = false;
            bool isFineRendering = false;
            string fileTypes = "PDF";
            int chunkSize = 200000;
            string sessionId = string.Empty;

            string faxNumber = "1" + notify.Value;

            InterFaxWs.InterFax fws = new InterFaxWs.InterFax();
            if (report.ReportData.Length > chunkSize)
            {
                fws.StartFileUpload(AppVars.FaxUserName, AppVars.FaxPassword, ref sessionId);
                if (sessionId.Length > 0)
                {
                    using (MemoryStream rMs = new MemoryStream(report.ReportData))
                    {
                        bool isLast = false;
                        bool uploadError = false;
                        int readSoFar = 0;

                        while (!isLast && !uploadError)
                        {
                            byte[] b = new byte[chunkSize];
                            int read = rMs.Read(b, 0, b.Length);
                            int uploaded = 0;
                            readSoFar += read;
                            isLast = (readSoFar == rMs.Length);
                            if (read < b.Length)
                            {
                                byte[] b1 = new byte[read];
                                for (int i = 0; i < read; i++) b1[i] = b[i];
                                uploaded = fws.UploadFileChunk(sessionId, b1, isLast);
                            }
                            else
                                uploaded = fws.UploadFileChunk(sessionId, b, isLast);
                            uploadError = (uploaded <= 0);
                        }

                        result = fws.SendfaxEx_2(AppVars.FaxUserName, AppVars.FaxPassword, faxNumber,
                            notify.ContactName, null, fileTypes, readSoFar.ToString() + "/sessionId=" + sessionId,
                            DateTime.MinValue, retriesToPerform, "", pageHeader, "", notificationRecord.SubjectLine,
                            "", pageSize, pageOrientation, isHighResolution, isFineRendering);
                    }
                }
            }
            else {
                result = fws.SendfaxEx_2(AppVars.FaxUserName, AppVars.FaxPassword, faxNumber,
                    notify.ContactName, report.ReportData, fileTypes, report.ReportData.Length.ToString(),
                    DateTime.MinValue, retriesToPerform, "", pageHeader, "", notificationRecord.SubjectLine,
                    "", pageSize, pageOrientation, isHighResolution, isFineRendering);
            }

            if (result > 0)
            {
                ReportDAO.RemoveProcessedNotificationRecords(notificationRecord);
                if (SysVars.isConsole) Console.WriteLine("Fax sent to {1} transaction ID : ", notify.Value, result);
            }
            else
                if (SysVars.isConsole) Console.WriteLine("Result of Fax {0} to {1}", result, notify.Value);
        }