示例#1
0
        public static string SendEmail(string pFile = "", ReportsProperty.SendEmailInfoCollection _SendMailCollection = null, serverside_report_requests _eftRequest = null)
        {
            string return_message = string.Empty;
            BrightVision.Mandrill.MandrillServerSide mandrillEx = new BrightVision.Mandrill.MandrillServerSide();
            mandrillEx.Key = ConfigurationManager.AppSettings["MandrillKey"].ToString();
            mandrillEx.FromName = _SendMailCollection.SenderName;
            mandrillEx.From = _SendMailCollection.SenderEmail;

            string mailTo = string.Empty;
            string mailCC = string.Empty;
            string mailBCC = string.Empty;
            string mailAttachmentUrl = !string.IsNullOrEmpty(pFile) ? "1" : string.Empty;
            string SMS = string.Empty;
            bool bolProceed = false;

            string xml = @"<message>
                            <sender_email>@@sender_mail</sender_email>
                            <email_to>@@emailTo</email_to>
                            <email_cc>@@emailCC</email_cc>
                            <email_bcc>@@emailBCC</email_bcc>
                            <subject>@@subject</subject>
                            <body>@@body</body>
                            <attachment_url>@@attachment_url</attachment_url>
                        </message>";

            /**
             * mail to.
             */
            for (int i = 0; i < _SendMailCollection.SendToContacts.Count; i++) {
                mandrillEx.TO.Add(FacadeCommon.IsNull(_SendMailCollection.SendToContacts[i].EmailAddress, ""), FacadeCommon.IsNull(_SendMailCollection.SendToContacts[i].Name, ""));
                if (mailTo != "")
                    mailTo += "\n";

                mailTo += "<email>" + _SendMailCollection.SendToContacts[i].EmailAddress + "</email>";
                bolProceed = true;

            }

            /**
             * mail bcc.
             */
            for (int i = 0; i < _SendMailCollection.BlindCarbonCopyContacts.Count; i++) {
                mandrillEx.BCC.Add(FacadeCommon.IsNull(_SendMailCollection.BlindCarbonCopyContacts[i].EmailAddress, ""), FacadeCommon.IsNull(_SendMailCollection.BlindCarbonCopyContacts[i].Name, ""));
                if (mailBCC != "")
                    mailBCC += "\n";

                mailBCC += "<email>" + _SendMailCollection.BlindCarbonCopyContacts[i].EmailAddress + "</email>";
                bolProceed = true;
            }

            xml = xml.Replace("@@sender_mail", mandrillEx.From)
                     .Replace("@@emailTo", mailTo)
                     .Replace("@@emailCC", mailCC)
                     .Replace("@@emailBCC", mailBCC)
                     .Replace("@@subject", _SendMailCollection.MailSubject)
                     .Replace("@@body", _SendMailCollection.MailContent)
                     .Replace("@@attachment_url", mailAttachmentUrl);

            long? message_log_id = null;
            message_log_id = FacadeCommon.SaveMail(xml, _eftRequest);

            if (bolProceed) {
                mandrillEx.Subject = _SendMailCollection.MailSubject;
                if (pFile != "")
                    mandrillEx.Attachment.Add("application/pdf", pFile);

                bool bolSend = mandrillEx.Send(ref return_message);
                if (bolSend)
                    UpdateMail(message_log_id, Guid.NewGuid().ToString(), return_message);
            }

            mandrillEx = null;
            return return_message;
        }
示例#2
0
        public static string SendSMS(ReportsProperty.SendSmsInfoCollection _SendSmsCollection = null, serverside_report_requests _eftRequest = null)
        {
            /*Sample XML
             * <SMS>
                    <contact>
                        <name>Dan</name>
                        <number>+6394992380</number>
                    </contact>
                    <contact>
                        <name>Venus</name>
                        <number>+639069163504</number>
                    </contact>
                </SMS>;
             */

            bool bolProceed = false;
            string smsRecipients = "";
            string xml = "";
            for (int i = 0; i < _SendSmsCollection.SmsContacts.Count; i++) {
                if (xml != "") xml += "\n";
                xml += "<contact><name>" + _SendSmsCollection.SmsContacts[i].Name + "</name><number>" + _SendSmsCollection.SmsContacts[i].MobileNo + "</number></contact>";
                if (smsRecipients != "") smsRecipients += "\n";
                smsRecipients += _SendSmsCollection.SmsContacts[i].Name;
                bolProceed = true;
            }

            if (bolProceed) {
                xml = "<SMS>" + xml + "</SMS>";
                LogEventSMS(xml, _SendSmsCollection.SmsMessage, _SendSmsCollection.ComputerName, _SendSmsCollection.ComputerIP, _eftRequest);
            }

            return xml;
        }