Beispiel #1
0
        public string SendMail1(string strFrom, string strTo, string strSubject, string strMessage,
                                string sHost, string sUserName, string sPassword, int iPort)
        {
            string strSonuc = "OK";

            OpenSmtp.Mail.MailMessage clsMail = new OpenSmtp.Mail.MailMessage();
            OpenSmtp.Mail.Smtp        clsSmtp = new OpenSmtp.Mail.Smtp();

            clsSmtp.Host        = sHost;
            clsSmtp.Username    = sUserName;
            clsSmtp.Password    = sPassword;
            clsSmtp.SendTimeout = 10000;
            clsSmtp.Port        = iPort;

            OpenSmtp.Mail.MailMessage clsMailMessage = new OpenSmtp.Mail.MailMessage();
            clsMailMessage.HtmlBody = strMessage;
            clsMailMessage.Subject  = strSubject;
            clsMailMessage.Charset  = "windows-1254";
            clsMailMessage.Priority = MailPriority.High.ToString();

            try
            {
                OpenSmtp.Mail.EmailAddress Gonderen = new OpenSmtp.Mail.EmailAddress(strFrom);
                clsMailMessage.From = Gonderen;

                OpenSmtp.Mail.EmailAddress Too = new OpenSmtp.Mail.EmailAddress(strTo);
                clsMailMessage.To.Add(Too);

                clsSmtp.SendMail(clsMailMessage);
            }
            catch (OpenSmtp.Mail.SmtpException ex)
            {
                if (ex != null)
                {
                    if (ex.Message != null)
                    {
                        strSonuc = "E-Posta gönderilemedi. Sebebi:" + ex.ToString();

                        //if (ex.Message.Length > 75)
                        //{
                        //    strSonuc = "E-Posta gönderilemedi. Sebebi:" + ex.Message.ToString().Substring(0, 75);
                        //}
                        //else
                        //{
                        //    strSonuc = "E-Posta gönderilemedi. Sebebi:" + ex.Message;
                        //}
                    }
                }
                else
                {
                    strSonuc = "E-Posta gönderilemedi. Bilinmeyen Hata";
                }
            }

            return(strSonuc);
        }
Beispiel #2
0
        private void SendMessage(string htmlBody)
        {
            // message obejct
            OpenSmtp.Mail.MailMessage msg = new OpenSmtp.Mail.MailMessage();
            msg.From = new OpenSmtp.Mail.EmailAddress("*****@*****.**");

            msg.To.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger1"));
            msg.To.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger2"));
            msg.To.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger3"));
            msg.To.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger4"));
            msg.To.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger5"));

            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger1"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger2"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger3"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger4"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger5"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger1"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger2"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger3"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger4"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger5"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger1"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger2"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger3"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger4"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger5"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger1"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger2"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger3"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger4"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger5"));

            msg.Subject = "OpenSmtp test";

            msg.HtmlBody = htmlBody;

            OpenSmtp.Mail.SmtpConfig.LogToText = false;

            OpenSmtp.Mail.Smtp smtp = new OpenSmtp.Mail.Smtp();
            smtp.SendTimeout = 60;
            smtp.Host        = "10.0.0.244";
//			if(FI.Common.AppConfig.SmtpUserName!=null && FI.Common.AppConfig.SmtpUserName!="")
//			{
//				smtp.Username=FI.Common.AppConfig.SmtpUserName;
//				smtp.Password=FI.Common.AppConfig.SmtpPassword;
//			}
            smtp.SendMail(msg);
        }
Beispiel #3
0
        private static void SendMail(string Subject, string Body, string MailTo)
        {
            OpenSmtp.Mail.MailMessage msg = new OpenSmtp.Mail.MailMessage();
            msg.From = new OpenSmtp.Mail.EmailAddress(FI.Common.AppConfig.SmtpSender);
            msg.To.Add(new OpenSmtp.Mail.EmailAddress(MailTo));
            msg.Subject  = Subject;
            msg.HtmlBody = Body;

            OpenSmtp.Mail.SmtpConfig.LogToText = false;
            OpenSmtp.Mail.Smtp smtp = new OpenSmtp.Mail.Smtp();
            smtp.SendTimeout = 600;
            smtp.Host        = FI.Common.AppConfig.SmtpServer;
            if (FI.Common.AppConfig.SmtpUserName != null && FI.Common.AppConfig.SmtpUserName != "")
            {
                smtp.Username = FI.Common.AppConfig.SmtpUserName;
                smtp.Password = FI.Common.AppConfig.SmtpPassword;
            }
            smtp.SendMail(msg);
        }
Beispiel #4
0
        public void Send(string subject, string body)
        {
            List<string> toList = StringPlus.GetSubStringList(StringPlus.ToDBC(to), ',');
            OpenSmtp.Mail.Smtp smtp = new OpenSmtp.Mail.Smtp(smtpServer, userName, pwd, smtpPort);
            foreach (string s in toList)
            {
                OpenSmtp.Mail.MailMessage msg = new OpenSmtp.Mail.MailMessage();
                msg.From = new OpenSmtp.Mail.EmailAddress(userName, authorName);

                msg.AddRecipient(s, OpenSmtp.Mail.AddressType.To);

                //设置邮件正文,并指定格式为 html 格式
                msg.HtmlBody = body;
                //设置邮件标题
                msg.Subject = subject;
                //指定邮件正文的编码
                msg.Charset = "gb2312";
                //发送邮件
                smtp.SendMail(msg);
            }
        }
Beispiel #5
0
        public void Send(string subject, string body)
        {
            List <string> toList = StringPlus.GetSubStringList(StringPlus.ToDBC(to), ',');

            OpenSmtp.Mail.Smtp smtp = new OpenSmtp.Mail.Smtp(smtpServer, userName, pwd, smtpPort);
            foreach (string s in toList)
            {
                OpenSmtp.Mail.MailMessage msg = new OpenSmtp.Mail.MailMessage();
                msg.From = new OpenSmtp.Mail.EmailAddress(userName, authorName);

                msg.AddRecipient(s, OpenSmtp.Mail.AddressType.To);

                //设置邮件正文,并指定格式为 html 格式
                msg.HtmlBody = body;
                //设置邮件标题
                msg.Subject = subject;
                //指定邮件正文的编码
                msg.Charset = "gb2312";
                //发送邮件
                smtp.SendMail(msg);
            }
        }
        public void SendReport(Report report , Contact[] contacts , Report.ExportFormat Format, DateTime getCachedFrom, out bool isFromCache)
        {
            isFromCache=false;

            if(report.IsProxy)
                throw new Exception("Report cannot be Proxy");

            if(contacts.Length==0)
                return;

            string fileNamePattern=report.GetType().Name + "_" +  report.ID.ToString() + "_";
            string fileName=fileNamePattern + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + Format.ToString();
            string cacheLookupFileName=fileNamePattern + getCachedFrom.ToString("yyyyMMddHHmmss") + "." + Format.ToString();
            string filePath=null;
            string reportString=null;

            // lookup cached report
            string[] lookupPaths=Directory.GetFiles(FI.Common.AppConfig.TempDir, fileNamePattern + "*." + Format.ToString());
            if(lookupPaths!=null)
            {
                foreach(string path in lookupPaths)
                {
                    string file=Path.GetFileName(path);
                    if(file.Length==cacheLookupFileName.Length && file.CompareTo(cacheLookupFileName)>0)
                    {
                        filePath=FI.Common.AppConfig.TempDir+ @"\" + file;
                        isFromCache=true;
                        break;
                    }
                }
            }
            if(filePath==null)
            {
                filePath=FI.Common.AppConfig.TempDir+ @"\" + fileName;
                report.Export(filePath, Format);
            }

            foreach(Contact cnt in contacts)
            {
                if(Format==Report.ExportFormat.HTML && reportString==null)
                {
                    if(cnt.DistributionFormat==Contact.DistributionFormatEnum.MessageBody || cnt.DistributionFormat==Contact.DistributionFormatEnum.Body_And_Attachment)
                    {
                        StreamReader sr=new StreamReader(filePath, System.Text.Encoding.Unicode, true);
                        if(sr!=null)
                        {
                            reportString=sr.ReadToEnd();
                            sr.Close();
                        }
                    }
                }

                //send via email
                try
                {
                    if(cnt.IsProxy)
                        cnt.Fetch();

                    // message object
                    OpenSmtp.Mail.MailMessage msg=new OpenSmtp.Mail.MailMessage();
                    msg.From=new OpenSmtp.Mail.EmailAddress(FI.Common.AppConfig.SmtpSender);
                    msg.To.Add(new OpenSmtp.Mail.EmailAddress(cnt.EMail));
                    msg.Subject=report.Name + " (" + report.Description + ")";

                    // attachment if ordered or report is not html
                    if(cnt.DistributionFormat==Contact.DistributionFormatEnum.Attachment ||
                        cnt.DistributionFormat==Contact.DistributionFormatEnum.Body_And_Attachment ||
                        Format!=Report.ExportFormat.HTML)
                    {
                        OpenSmtp.Mail.Attachment att=new OpenSmtp.Mail.Attachment(filePath);
                        //att.Encoding=System.Web.Mail.MailEncoding.UUEncode;
                        msg.Attachments.Add(att);
                    }

                    // message body (if retport is html)
                    if(Format==Report.ExportFormat.HTML &&
                        (cnt.DistributionFormat==Contact.DistributionFormatEnum.MessageBody ||
                        cnt.DistributionFormat==Contact.DistributionFormatEnum.Body_And_Attachment))
                    {
                        msg.HtmlBody=reportString;
                    }

            //					msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "0"); //This is crucial. put 0 there
            //					msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 90);

                    OpenSmtp.Mail.SmtpConfig.LogToText=false;

                    OpenSmtp.Mail.Smtp smtp=new OpenSmtp.Mail.Smtp();
                    smtp.SendTimeout=600;
                    smtp.Host=FI.Common.AppConfig.SmtpServer;
                    if(FI.Common.AppConfig.SmtpUserName!=null && FI.Common.AppConfig.SmtpUserName!="")
                    {
                        smtp.Username=FI.Common.AppConfig.SmtpUserName;
                        smtp.Password=FI.Common.AppConfig.SmtpPassword;
                    }
                    smtp.SendMail(msg);
            //					System.Web.Mail.SmtpMail.SmtpServer=FI.Common.AppConfig.SmtpServer;
            //					System.Web.Mail.SmtpMail.Send(msg);
                }
                catch(Exception exc)
                {
                    // because real exception is inside:
                    while(exc.InnerException!=null)
                    {
                        exc=exc.InnerException;
                    }

                    Common.LogWriter.Instance.WriteEventLogEntry(exc);
                    throw exc;
                }

            }
        }
        public void PingOlapSystem(string Mdx, string MailTo)
        {
            bool failure = false;

            System.IO.StringWriter sw = new System.IO.StringWriter();

            // get all companies
            FI.Common.DataAccess.IUsersDA usersDac = DataAccessFactory.Instance.GetUsersDA();
            System.Data.DataTable         table    = usersDac.ReadCompanies();
            if (table == null || table.Rows.Count == 0)
            {
                return;
            }

            sw.WriteLine("<html>");
            sw.WriteLine("Failed Ping Queries (" + System.DateTime.Today.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString() + ")");
            sw.WriteLine("<br><br>");
            sw.WriteLine("<table border=1 width=100%>");

            try
            {
                foreach (System.Data.DataRow row in table.Rows)
                {
                    if ((bool)row["Ping"] == true)
                    {
                        string company  = row["ShortName"].ToString();
                        string server   = row["OlapServer"].ToString();
                        string database = row["OlapDatabase"].ToString();

                        try
                        {
                            string taskGuid = Guid.NewGuid().ToString();
                            string taskTag  = string.Format("Ping");

                            FI.Common.DataAccess.IOlapSystemDA olapDac = DataAccessFactory.Instance.GetOlapSystemDA();
                            olapDac.BuildCellset(Mdx, server, database, taskGuid, taskTag);
                        }
                        catch (Exception exc)
                        {
                            failure = true;

                            sw.Write("<tr>");
                            sw.Write("<td>");
                            sw.Write(company);
                            sw.Write("</td><td>");
                            sw.Write(exc.Message);
                            sw.Write("</td>");
                            sw.WriteLine("</tr>");

                            Common.LogWriter.Instance.WriteEventLogEntry(exc);
                        }
                    }
                }
            }
            catch (Exception exc)            //more common exception
            {
                failure = true;

                sw.Write("<tr>");
                sw.Write(exc.Message);
                sw.Write("</td>");
                sw.WriteLine("</tr>");

                Common.LogWriter.Instance.WriteEventLogEntry(exc);
            }

            sw.WriteLine("</table></html>");


            //send via email
            if (failure)
            {
                try
                {
                    // message
                    OpenSmtp.Mail.MailMessage msg = new OpenSmtp.Mail.MailMessage();
                    msg.From = new OpenSmtp.Mail.EmailAddress(FI.Common.AppConfig.SmtpSender);
                    msg.To.Add(new OpenSmtp.Mail.EmailAddress(MailTo));
                    msg.Subject  = "Failed Ping Queries";
                    msg.Priority = "High";
                    msg.HtmlBody = sw.ToString();

                    // smtp host
                    OpenSmtp.Mail.Smtp smtp = new OpenSmtp.Mail.Smtp();
                    smtp.Host = FI.Common.AppConfig.SmtpServer;
                    if (FI.Common.AppConfig.SmtpUserName != null && FI.Common.AppConfig.SmtpUserName != "")
                    {
                        smtp.Username = FI.Common.AppConfig.SmtpUserName;
                        smtp.Password = FI.Common.AppConfig.SmtpPassword;
                    }
                    smtp.SendMail(msg);
                }
                catch (Exception exc)
                {
                    // because real exception is inside:
                    while (exc.InnerException != null)
                    {
                        exc = exc.InnerException;
                    }

                    throw exc;
                }
            }
        }
Beispiel #8
0
        private System.String SendMailOpenSmtp(anmar.SharpWebMail.EmailServerInfo server)
        {
            System.String             message     = null;
            System.Text.Encoding      encoding    = (System.Text.Encoding)Application["sharpwebmail/send/message/charset"];
            OpenSmtp.Mail.MailMessage mailMessage = new OpenSmtp.Mail.MailMessage();
            mailMessage.Charset = encoding.HeaderName;
            mailMessage.From    = new OpenSmtp.Mail.EmailAddress(this.GetFromAddress(), this.fromname.Value);
            System.String[] tokens = anmar.SharpMimeTools.ABNF.address_regex.Split(this.toemail.Value);
            foreach (System.String token in tokens)
            {
                if (anmar.SharpMimeTools.ABNF.address_regex.IsMatch(token))
                {
                    mailMessage.To.Add(new OpenSmtp.Mail.EmailAddress(token.Trim()));
                }
            }
            mailMessage.Subject = this.subject.Value.Trim();
            System.String format = Request.Form["format"];
            if (format != null && format.Equals("html"))
            {
                mailMessage.HtmlBody = bodyStart + FCKEditor.Value + bodyEnd;
            }
            else
            {
                mailMessage.Body = FCKEditor.Value;
            }

            if (this._headers != null)
            {
                // RFC 2822 3.6.4. Identification fields
                OpenSmtp.Mail.MailHeader references = new OpenSmtp.Mail.MailHeader("References", System.String.Empty);
                if (this._headers["Message-ID"] != null)
                {
                    mailMessage.AddCustomHeader("In-Reply-To", this._headers["Message-ID"]);
                    references.Body = this._headers["Message-ID"];
                }
                if (this._headers["References"] != null)
                {
                    references.Body = System.String.Concat(this._headers["References"], " ", references.Body).Trim();
                }
                else if (this._headers["In-Reply-To"] != null && this._headers["In-Reply-To"].IndexOf('>') == this._headers["In-Reply-To"].LastIndexOf('>'))
                {
                    references.Body = System.String.Concat(this._headers["In-Reply-To"], " ", references.Body).Trim();
                }
                if (!references.Body.Equals(System.String.Empty))
                {
                    mailMessage.AddCustomHeader(references);
                }
            }
            mailMessage.AddCustomHeader("X-Mailer", System.String.Concat(Application["product"], " ", Application["version"]));
            this.ProcessMessageAttachments(mailMessage);
            try {
                if (log.IsDebugEnabled)
                {
                    log.Debug(System.String.Concat("Sending message. engine: opensmtp , protocol: ", server.Protocol));
                }
                OpenSmtp.Mail.Smtp SmtpMail = null;
                if (server.Protocol.Equals(anmar.SharpWebMail.ServerProtocol.SmtpAuth))
                {
                    anmar.SharpWebMail.IEmailClient client = (anmar.SharpWebMail.IEmailClient)Session["client"];
                    SmtpMail = new OpenSmtp.Mail.Smtp(server.Host, client.UserName, client.Password, server.Port);
                }
                else
                {
                    SmtpMail = new OpenSmtp.Mail.Smtp(server.Host, server.Port);
                }
                SmtpMail.SendMail(mailMessage);
                SmtpMail = null;
                if (log.IsDebugEnabled)
                {
                    log.Debug("Message sent");
                }
            } catch (System.Exception e) {
                message = e.Message;
                if (log.IsErrorEnabled)
                {
                    log.Error(System.String.Concat("Error sending message. engine: opensmtp , protocol: ", server.Protocol), e);
                }
            }
            mailMessage = null;
            return(message);
        }
Beispiel #9
0
        private void SendMessage(string htmlBody)
        {
            // message obejct
            OpenSmtp.Mail.MailMessage msg=new OpenSmtp.Mail.MailMessage();
            msg.From=new OpenSmtp.Mail.EmailAddress("*****@*****.**");

            msg.To.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger1"));
            msg.To.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger2"));
            msg.To.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger3"));
            msg.To.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger4"));
            msg.To.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger5"));

            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger1"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger2"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger3"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger4"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger5"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger1"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger2"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger3"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger4"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger5"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger1"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger2"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger3"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger4"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger5"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger1"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger2"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger3"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger4"));
            msg.CC.Add(new OpenSmtp.Mail.EmailAddress("*****@*****.**", "Ger5"));

            msg.Subject="OpenSmtp test";

            msg.HtmlBody=htmlBody;

            OpenSmtp.Mail.SmtpConfig.LogToText=false;

            OpenSmtp.Mail.Smtp smtp=new OpenSmtp.Mail.Smtp();
            smtp.SendTimeout=60;
            smtp.Host="10.0.0.244";
            //			if(FI.Common.AppConfig.SmtpUserName!=null && FI.Common.AppConfig.SmtpUserName!="")
            //			{
            //				smtp.Username=FI.Common.AppConfig.SmtpUserName;
            //				smtp.Password=FI.Common.AppConfig.SmtpPassword;
            //			}
            smtp.SendMail(msg);
        }
        public void SendReport(Report report, Contact[] contacts, Report.ExportFormat Format, DateTime getCachedFrom, out bool isFromCache)
        {
            isFromCache = false;

            if (report.IsProxy)
            {
                throw new Exception("Report cannot be Proxy");
            }

            if (contacts.Length == 0)
            {
                return;
            }

            string fileNamePattern     = report.GetType().Name + "_" + report.ID.ToString() + "_";
            string fileName            = fileNamePattern + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + Format.ToString();
            string cacheLookupFileName = fileNamePattern + getCachedFrom.ToString("yyyyMMddHHmmss") + "." + Format.ToString();
            string filePath            = null;
            string reportString        = null;

            // lookup cached report
            string[] lookupPaths = Directory.GetFiles(FI.Common.AppConfig.TempDir, fileNamePattern + "*." + Format.ToString());
            if (lookupPaths != null)
            {
                foreach (string path in lookupPaths)
                {
                    string file = Path.GetFileName(path);
                    if (file.Length == cacheLookupFileName.Length && file.CompareTo(cacheLookupFileName) > 0)
                    {
                        filePath    = FI.Common.AppConfig.TempDir + @"\" + file;
                        isFromCache = true;
                        break;
                    }
                }
            }
            if (filePath == null)
            {
                filePath = FI.Common.AppConfig.TempDir + @"\" + fileName;
                report.Export(filePath, Format);
            }


            foreach (Contact cnt in contacts)
            {
                if (Format == Report.ExportFormat.HTML && reportString == null)
                {
                    if (cnt.DistributionFormat == Contact.DistributionFormatEnum.MessageBody || cnt.DistributionFormat == Contact.DistributionFormatEnum.Body_And_Attachment)
                    {
                        StreamReader sr = new StreamReader(filePath, System.Text.Encoding.Unicode, true);
                        if (sr != null)
                        {
                            reportString = sr.ReadToEnd();
                            sr.Close();
                        }
                    }
                }

                //send via email
                try
                {
                    if (cnt.IsProxy)
                    {
                        cnt.Fetch();
                    }

                    // message object
                    OpenSmtp.Mail.MailMessage msg = new OpenSmtp.Mail.MailMessage();
                    msg.From = new OpenSmtp.Mail.EmailAddress(FI.Common.AppConfig.SmtpSender);
                    msg.To.Add(new OpenSmtp.Mail.EmailAddress(cnt.EMail));
                    msg.Subject = report.Name + " (" + report.Description + ")";

                    // attachment if ordered or report is not html
                    if (cnt.DistributionFormat == Contact.DistributionFormatEnum.Attachment ||
                        cnt.DistributionFormat == Contact.DistributionFormatEnum.Body_And_Attachment ||
                        Format != Report.ExportFormat.HTML)
                    {
                        OpenSmtp.Mail.Attachment att = new OpenSmtp.Mail.Attachment(filePath);
                        //att.Encoding=System.Web.Mail.MailEncoding.UUEncode;
                        msg.Attachments.Add(att);
                    }

                    // message body (if retport is html)
                    if (Format == Report.ExportFormat.HTML &&
                        (cnt.DistributionFormat == Contact.DistributionFormatEnum.MessageBody ||
                         cnt.DistributionFormat == Contact.DistributionFormatEnum.Body_And_Attachment))
                    {
                        msg.HtmlBody = reportString;
                    }

//					msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "0"); //This is crucial. put 0 there
//					msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 90);

                    OpenSmtp.Mail.SmtpConfig.LogToText = false;

                    OpenSmtp.Mail.Smtp smtp = new OpenSmtp.Mail.Smtp();
                    smtp.SendTimeout = 600;
                    smtp.Host        = FI.Common.AppConfig.SmtpServer;
                    if (FI.Common.AppConfig.SmtpUserName != null && FI.Common.AppConfig.SmtpUserName != "")
                    {
                        smtp.Username = FI.Common.AppConfig.SmtpUserName;
                        smtp.Password = FI.Common.AppConfig.SmtpPassword;
                    }
                    smtp.SendMail(msg);
//					System.Web.Mail.SmtpMail.SmtpServer=FI.Common.AppConfig.SmtpServer;
//					System.Web.Mail.SmtpMail.Send(msg);
                }
                catch (Exception exc)
                {
                    // because real exception is inside:
                    while (exc.InnerException != null)
                    {
                        exc = exc.InnerException;
                    }

                    Common.LogWriter.Instance.WriteEventLogEntry(exc);
                    throw exc;
                }
            }
        }
Beispiel #11
0
        private System.String SendMailOpenSmtp( anmar.SharpWebMail.EmailServerInfo server )
        {
            System.String message = null;
            OpenSmtp.Mail.MailMessage mailMessage = new OpenSmtp.Mail.MailMessage();
            mailMessage.From = new OpenSmtp.Mail.EmailAddress(this.GetFromAddress(), this.fromname.Value);
            System.String[] tokens = anmar.SharpMimeTools.ABNF.address_regex.Split(this.toemail.Value);
            foreach ( System.String token in tokens ) {
                if ( anmar.SharpMimeTools.ABNF.address_regex.IsMatch(token ) )
                    mailMessage.To.Add (new OpenSmtp.Mail.EmailAddress(token.Trim()));
            }
            mailMessage.Subject = this.subject.Value.Trim();
            System.String format = Request.Form["format"];
            if ( format!=null && format.Equals("html") ) {
                mailMessage.HtmlBody = bodyStart + FCKEditor.Value + bodyEnd;
            } else {
                mailMessage.Body = FCKEditor.Value;
            }

            if ( this._headers != null ) {
                // RFC 2822 3.6.4. Identification fields
                OpenSmtp.Mail.MailHeader references = new OpenSmtp.Mail.MailHeader("References", System.String.Empty);
                if ( this._headers["Message-ID"]!=null ) {
                    mailMessage.AddCustomHeader("In-Reply-To", this._headers["Message-ID"]);
                    references.Body = this._headers["Message-ID"];
                }
                if ( this._headers["References"]!=null ) {
                    references.Body = System.String.Concat(this._headers["References"], " ", references.Body).Trim();
                } else if ( this._headers["In-Reply-To"]!=null && this._headers["In-Reply-To"].IndexOf('>')==this._headers["In-Reply-To"].LastIndexOf('>') ) {
                    references.Body = System.String.Concat(this._headers["In-Reply-To"], " ", references.Body).Trim();
                }
                if ( !references.Body.Equals(System.String.Empty) )
                    mailMessage.AddCustomHeader(references);
            }
            mailMessage.AddCustomHeader("X-Mailer", System.String.Concat (Application["product"], " ", Application["version"]));
            this.ProcessMessageAttachments(mailMessage);
            try {
                if ( log.IsDebugEnabled) log.Error ( "Sending message" );
                OpenSmtp.Mail.Smtp SmtpMail = null;
                if ( server.Protocol.Equals(anmar.SharpWebMail.ServerProtocol.SmtpAuth) ) {
                    anmar.SharpWebMail.IEmailClient client = (anmar.SharpWebMail.IEmailClient)Session["client"];
                    SmtpMail = new OpenSmtp.Mail.Smtp(server.Host, client.UserName, client.Password, server.Port);
                } else
                    SmtpMail = new OpenSmtp.Mail.Smtp(server.Host, server.Port);
                SmtpMail.SendMail(mailMessage);
                SmtpMail=null;
                if ( log.IsDebugEnabled) log.Error ( "Message sent" );
            } catch (System.Exception e) {
                message = e.Message;
                if ( log.IsErrorEnabled ) log.Error ( "Error sending message", e );
            }
            mailMessage = null;
            return message;
        }
        public void PingOlapSystem(string Mdx , string MailTo)
        {
            bool failure=false;

            System.IO.StringWriter sw=new System.IO.StringWriter();

            // get all companies
            FI.Common.DataAccess.IUsersDA usersDac=DataAccessFactory.Instance.GetUsersDA();
            System.Data.DataTable table=usersDac.ReadCompanies();
            if(table==null || table.Rows.Count==0)
                return;

            sw.WriteLine("<html>");
            sw.WriteLine("Failed Ping Queries (" + System.DateTime.Today.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString() + ")");
            sw.WriteLine("<br><br>");
            sw.WriteLine("<table border=1 width=100%>");

            try
            {
                foreach(System.Data.DataRow row in table.Rows)
                {
                    if( (bool)row["Ping"]==true)
                    {
                        string company=row["ShortName"].ToString();
                        string server=row["OlapServer"].ToString();
                        string database=row["OlapDatabase"].ToString();

                        try
                        {
                            string taskGuid=Guid.NewGuid().ToString();
                            string taskTag=string.Format("Ping");

                            FI.Common.DataAccess.IOlapSystemDA olapDac=DataAccessFactory.Instance.GetOlapSystemDA();
                            olapDac.BuildCellset(Mdx , server , database, taskGuid, taskTag);
                        }
                        catch(Exception exc)
                        {
                            failure=true;

                            sw.Write("<tr>");
                            sw.Write("<td>");
                            sw.Write(company);
                            sw.Write("</td><td>");
                            sw.Write(exc.Message);
                            sw.Write("</td>");
                            sw.WriteLine("</tr>");

                            Common.LogWriter.Instance.WriteEventLogEntry(exc);
                        }
                    }
                }
            }
            catch(Exception exc) //more common exception
            {
                failure=true;

                sw.Write("<tr>");
                sw.Write(exc.Message);
                sw.Write("</td>");
                sw.WriteLine("</tr>");

                Common.LogWriter.Instance.WriteEventLogEntry(exc);
            }

            sw.WriteLine("</table></html>");

            //send via email
            if(failure)
            {
                try
                {
                    // message
                    OpenSmtp.Mail.MailMessage msg=new OpenSmtp.Mail.MailMessage();
                    msg.From=new OpenSmtp.Mail.EmailAddress(FI.Common.AppConfig.SmtpSender);
                    msg.To.Add(new OpenSmtp.Mail.EmailAddress(MailTo));
                    msg.Subject="Failed Ping Queries";
                    msg.Priority="High";
                    msg.HtmlBody=sw.ToString();

                    // smtp host
                    OpenSmtp.Mail.Smtp smtp=new OpenSmtp.Mail.Smtp();
                    smtp.Host=FI.Common.AppConfig.SmtpServer;
                    if(FI.Common.AppConfig.SmtpUserName!=null && FI.Common.AppConfig.SmtpUserName!="")
                    {
                        smtp.Username=FI.Common.AppConfig.SmtpUserName;
                        smtp.Password=FI.Common.AppConfig.SmtpPassword;
                    }
                    smtp.SendMail(msg);
                }
                catch(Exception exc)
                {
                    // because real exception is inside:
                    while(exc.InnerException!=null)
                    {
                        exc=exc.InnerException;
                    }

                    throw exc;
                }
            }
        }
Beispiel #13
0
        private static void SendMail(string Subject , string Body , string MailTo)
        {
            OpenSmtp.Mail.MailMessage msg=new OpenSmtp.Mail.MailMessage();
            msg.From=new OpenSmtp.Mail.EmailAddress(FI.Common.AppConfig.SmtpSender);
            msg.To.Add(new OpenSmtp.Mail.EmailAddress(MailTo));
            msg.Subject=Subject;
            msg.HtmlBody=Body;

            OpenSmtp.Mail.SmtpConfig.LogToText=false;
            OpenSmtp.Mail.Smtp smtp=new OpenSmtp.Mail.Smtp();
            smtp.SendTimeout=600;
            smtp.Host=FI.Common.AppConfig.SmtpServer;
            if(FI.Common.AppConfig.SmtpUserName!=null && FI.Common.AppConfig.SmtpUserName!="")
            {
                smtp.Username=FI.Common.AppConfig.SmtpUserName;
                smtp.Password=FI.Common.AppConfig.SmtpPassword;
            }
            smtp.SendMail(msg);
        }