Exemplo n.º 1
0
        /// <summary>
        /// Send single mail
        /// </summary>
        /// <param name="databaseName">database Name</param>
        /// <param name="pid">Primary Key</param>
        /// <param name="fromName">sender</param>
        /// <param name="emailFrom">emailFrom</param>
        /// <param name="emailTo">emailTo</param>
        /// <param name="emailSubject">emailSubject</param>
        /// <param name="emailBody">emailBody</param>
        /// <returns></returns>  
        public String sendSingleEmail(String databaseName, String pid, String fromName, String emailFrom, String emailTo, String emailSubject, String emailBody)
        {
            logger.Debug("************send Single Mail***************");
            String result = OK_RESULT;
            try
            {
                if (String.IsNullOrEmpty(databaseName))
                {
                    return "No project Name";
                }
                if (String.IsNullOrEmpty(pid))
                {
                    return "No primary Id";
                }
                if (String.IsNullOrEmpty(emailFrom))
                {
                    return "No from Address";
                }
                if (String.IsNullOrEmpty(emailTo))
                {
                    return "No to Address";
                }
                ContactDatabaseAction contactDatabaseAction = new ContactDatabaseAction(client, userName, password, oWebProxy);
                String contactDatabaseId = contactDatabaseAction.createContactDatabase(databaseName);

                WorkspaceAction workspaceAction = new WorkspaceAction(client, userName, password, oWebProxy);
                String workspaceId = workspaceAction.createWorkspace(contactDatabaseId, databaseName);

                ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password, oWebProxy);
                Hashtable ht = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId);
                String toEmailFieldId; //Properties.Settings.Default.toEmailFieldId;// "MTExMzYxMTEfCGWCBaFKyA";
                if (ht[EMAIL] != null)
                {
                    toEmailFieldId = ht[EMAIL].ToString();
                }
                else
                {
                    return "Database:" + databaseName + " is not exist";
                }

                const string pattern = "\\{.+?\\}";
                List<string> tempList = Regex.Matches(emailBody, pattern).Cast<Match>().Select(a => a.Value).ToList();
                foreach (string str in tempList)
                {
                    emailBody = emailBody.Replace(str, str.ToLower());
                }
                //查找<A的html标记,如果里面没有title属性,则增加这个属性.
                emailBody = Util.addTitleInAFlagHtml(emailBody);

                String sequence = DateTime.Now.ToString("yyyyMMddhhmmss");
                //  ContactGroupAction contactGroupAction = new ContactGroupAction(client, userName, password);
                //String contactGroupId = contactGroupAction.createContactGroup(contactDatabaseId, emailId, emailId);
                ContactAction contactAction = new ContactAction(client, userName, password, oWebProxy);
                ArrayList list = new ArrayList();
                String jsonStr = PID + "#" + pid + "," + EMAIL + "#" + emailTo;
                list.Add(jsonStr);
                String contactId = contactAction.createContact(contactDatabaseId, list);

                DirectEmailTypeAction directEmailTypeAction = new DirectEmailTypeAction(client, userName, password, oWebProxy);
                String directEmailTypeId = directEmailTypeAction.createDirectEmailType(workspaceId, "Email Type for " + databaseName, "mail_type_" + databaseName, emailFrom, fromName, toEmailFieldId);

                DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy);
                String directEmailId = directEmailAction.createDirectEmail(directEmailTypeId, "Mail" + sequence, "mail" + sequence, emailSubject, "Send mail", fromName, emailFrom, emailBody);

                PublishingAction publishingAction = new PublishingAction(client, userName, password, oWebProxy);
                String publishId = publishingAction.publishTransactionalEmail(contactId, directEmailId,DateTime.Now);

                logger.Debug("publishId=" + publishId);

            }
            catch (Exception ex)
            {
                result = ex.Message;
                logger.Debug("error happen in send mail, error is " + result);
                // return ex.Message;

            }
            logger.Debug("************end sendMail ************");
            return result;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send single sms
        /// </summary>
        /// <param name="databaseName">database Name</param>      
        /// <param name="pid">primary key</param>  
        /// <param name="fromName">sender</param>
        /// <param name="emailFrom">emailFrom</param>
        /// <param name="emailTo">emailTo</param>
        /// <param name="emailSubject">emailSubject</param>
        /// <param name="emailBody">emailBody</param>
        /// <returns></returns>  
        public String sendSingleSms(String databaseName, String pid, String fromName, String smsTo, String message, String alternativeMessage)
        {
            logger.Debug("************send Single Mail***************");
            String result = OK_RESULT;
            try
            {
                if (String.IsNullOrEmpty(databaseName))
                {
                    return "No database Name";
                }
                if (String.IsNullOrEmpty(pid))
                {
                    return "No primary key";
                }

                if (String.IsNullOrEmpty(smsTo))
                {
                    return "No to Address";
                }
                ContactDatabaseAction contactDatabaseAction = new ContactDatabaseAction(client, userName, password, oWebProxy);
                String contactDatabaseId = contactDatabaseAction.createContactDatabase(databaseName);

                WorkspaceAction workspaceAction = new WorkspaceAction(client, userName, password, oWebProxy);
                String workspaceId = workspaceAction.createWorkspace(contactDatabaseId, databaseName);

                ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password, oWebProxy);
                Hashtable ht = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId);
                String toEmailFieldId; //Properties.Settings.Default.toEmailFieldId;// "MTExMzYxMTEfCGWCBaFKyA";
                if (ht[EMAIL] != null)
                {
                    toEmailFieldId = ht[EMAIL].ToString();
                }
                else
                {
                    return "Database:" + databaseName + " is not exist";
                }

                String sequence = DateTime.Now.ToString("yyyyMMddhhmmss");
                //  ContactGroupAction contactGroupAction = new ContactGroupAction(client, userName, password);
                //String contactGroupId = contactGroupAction.createContactGroup(contactDatabaseId, emailId, emailId);
                ContactAction contactAction = new ContactAction(client, userName, password, oWebProxy);
                ArrayList list = new ArrayList();
                String jsonStr = PID + "#" + pid + "," + EMAIL + "#" + "" + "," + "Mobile" + "#" + smsTo;
                list.Add(jsonStr);
                String contactId = contactAction.createContact(contactDatabaseId, list);

                SmsTypeAction smsTypeAction = new SmsTypeAction(client, userName, password, oWebProxy);
                String smsTypeId = smsTypeAction.createSmsType(workspaceId, "SMS Type for " + databaseName, "sms_type_" + databaseName, fromName, toEmailFieldId);

                //  SmsMessageAction smsMessageAction = new SmsMessageAction(client, userName, password);
                //  String directEmailId = directEmailAction.createDirectEmail(directEmailId, "IPSOS SMS" + sequence, "ipsos_mail" + sequence, emailSubject, "Send mail by IPSOS", fromName, emailFrom, emailBody);

                //  PublishingAction publishingAction = new PublishingAction(client, userName, password);
                //  String publishId = publishingAction.publishTransactionalEmail(contactId, directEmailId);

                //  logger.Debug("publishId=" + publishId);

            }
            catch (Exception ex)
            {
                result = ex.Message;
                logger.Debug("error happen in send mail, error is " + result);
                // return ex.Message;

            }
            logger.Debug("************end sendMail ************");
            return result;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get feedback information
        /// </summary>
        /// <param name="customerName">customer Name</param>
        /// <param name="startTime">StartTime</param>
        /// <param name="endTime">End time</param>
        /// <param name="searchConditions">searchConditions</param>
        /// <returns>all of the information, including sent, bounced, 
        /// clicked and opened</returns>
        private XDocument queryFeedbackInfo(String customerName, DateTime startTime, DateTime endTime, Hashtable searchConditions)
        {
            //String BouncedFormat = "email"; "name"; "Email address of bounced message"; "Bounce date"; "Bounce code"; "Bounce decription"; "Hard bounce"; "Job ID";
            //String OpenedFormat  = "email"; "name"; "Rendered"; "Opened"; "IP address"; "Browser"; "OS"; "Job ID";
            //String ClickedFormat = "email"; "name"; "clicked";  "linkid"; "IP address"; "browser";       "Job ID"
            if (logger.IsDebugEnabled)
            {
                logger.Debug("queryFeedbackInfo:customerName=" + customerName + ",startTime=" + startTime.ToLongTimeString() + ",endTime=" + endTime.ToLongTimeString());
            }
            String result;
            XDocument doc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"));
            try
            {
                Action.ContactDatabaseAction contactDatabaseAction = new ContactDatabaseAction(client, userName, password, oWebProxy);
                String contactDatabaseId = contactDatabaseAction.getDatabaseIdByName(customerName);

                ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password, oWebProxy);
                Hashtable ht = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId);
                //String toEmailFieldId = contactDatabaseFieldAction.getDatabaseEmailId(contactDatabaseId);

                cn.tripolis.dialogue.export.ContactExportRequest request = new cn.tripolis.dialogue.export.ContactExportRequest
                    {
                        contactDatabaseId = contactDatabaseId,
                        timeRange = new cn.tripolis.dialogue.export.TimeRange { startTime = startTime, endTime = endTime }
                    };

                var xroot = new XElement("FeedbackReport");

                logger.Debug("******exportSent*****");
                request.returnContactFields = new cn.tripolis.dialogue.export.ReturnContactFields
                    {
                        contactDatabaseFieldIds = new String[ht.Keys.Count]
                    };
                int index = 0;
                foreach (String value in ht.Values)
                {
                    request.returnContactFields.contactDatabaseFieldIds.SetValue(value, index++);
                }
                RawDataResponse response = exportService.exportSent(request);
                result = System.Text.Encoding.UTF8.GetString(response.data);
                XElement element = Util.convertCsvToXmlElement(result.Replace("\"", ""), new[] { ";" }, "exportSent", searchConditions);
                xroot.Add(element);

                request.returnContactFields.contactDatabaseFieldIds = null;


                request.returnContactFields = new cn.tripolis.dialogue.export.ReturnContactFields
                    {
                        returnAllContactFields = true,
                        returnAllContactFieldsSpecified = true
                    };

                logger.Debug("******exportBounced*****");
                response = exportService.exportBounced(request);
                result = System.Text.Encoding.UTF8.GetString(response.data);
                element = Util.convertCsvToXmlElement(result.Replace("\"", ""), new[] { ";" }, "exportBounced", searchConditions);
                xroot.Add(element);


                logger.Debug("******exportOpened*****");
                response = exportService.exportOpened(request);
                result = System.Text.Encoding.UTF8.GetString(response.data);
                element = Util.convertCsvToXmlElement(result.Replace("\"", ""), new[] { ";" }, "exportOpened", searchConditions);
                xroot.Add(element);


                logger.Debug("******exportClicked*****");
                response = exportService.exportClicked(request);
                result = System.Text.Encoding.UTF8.GetString(response.data);
                element = Util.convertCsvToXmlElement(result.Replace("\"", ""), new[] { ";" }, "exportClicked", searchConditions);
                xroot.Add(element);
                doc.Add(xroot);
                result = doc.ToString();
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                result = ex.Detail.InnerXml;
                throw new Exception(result);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                throw new Exception(result);
            }
            if (logger.IsDebugEnabled)
            {
                logger.Debug(result);
            }
            return doc;
        }
Exemplo n.º 4
0
        /// <summary>
        /// send batch mail
        /// </summary>
        /// <param name="databaseName">databaseName</param>
        /// <param name="mailData">mailData</param>
        /// <returns></returns>
        public String sendBatchMail(String databaseName, MailData mailData)
        {
            logger.Debug("************send Batch Mail***************");
            String result = OK_RESULT;
            try
            {
                if (String.IsNullOrEmpty(databaseName))
                {
                    return "No database Name";
                }
                if (mailData == null || mailData.ContactJsonList == null || mailData.ContactJsonList.Count <= 0)
                {
                    return "No Contact";
                }
                ContactDatabaseAction contactDatabaseAction = new ContactDatabaseAction(client, userName, password, oWebProxy);
                String contactDatabaseId = contactDatabaseAction.createContactDatabase(databaseName);


                WorkspaceAction workspaceAction = new WorkspaceAction(client, userName, password, oWebProxy);
                String workspaceId = workspaceAction.createWorkspace(contactDatabaseId, databaseName);

                ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password, oWebProxy);
                Hashtable ht = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId);

                String toEmailFieldId; //Properties.Settings.Default.toEmailFieldId;// "MTExMzYxMTEfCGWCBaFKyA";
                if (ht[EMAIL] != null)
                {
                    toEmailFieldId = ht[EMAIL].ToString();
                }
                else
                {
                    return "Database:" + databaseName + " is not exist";
                }

                const string pattern = "\\{.+?\\}";
                List<string> tempList = Regex.Matches(mailData.mailBody, pattern).Cast<Match>().Select(a => a.Value).ToList();
                foreach (string str in tempList)
                {
                    mailData.mailBody = mailData.mailBody.Replace(str, str.ToLower());
                }
                //查找<A的html标记,如果里面没有title属性,则增加这个属性.
                mailData.mailBody = Util.addTitleInAFlagHtml(mailData.mailBody);


                String sequence = DateTime.Now.ToString("yyyyMMddhhmmss");
                ContactGroupAction contactGroupAction = new ContactGroupAction(client, userName, password, oWebProxy);

                // ContactGroup[] temp = contactGroupAction.getContactGroup(contactDatabaseId);

                String contactGroupId = contactGroupAction.createContactGroup(contactDatabaseId, "Mail Group" + sequence, "mail_group" + sequence);

                this.importContact(contactDatabaseId, contactGroupId, mailData);

                DirectEmailTypeAction directEmailTypeAction = new DirectEmailTypeAction(client, userName, password, oWebProxy);
                String directEmailTypeId = directEmailTypeAction.createDirectEmailType(workspaceId, "Email Type for" + databaseName, "mail_type_" + databaseName, mailData.fromAddress, mailData.sender, toEmailFieldId);

                DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy);
                String directEmailId = directEmailAction.createDirectEmail(directEmailTypeId, "Mail" + sequence, "mail" + sequence, mailData.subject, "Send mail", mailData.sender, mailData.fromAddress, mailData.mailBody);

                PublishingAction publishingAction = new PublishingAction(client, userName, password, oWebProxy);
                String publishId = publishingAction.publishingEmail(contactGroupId, directEmailId, DateTime.Now);

                logger.Debug("publishId=" + publishId);

            }
            catch (Exception ex)
            {
                result = ex.Message;
                logger.Debug("error happen in send mail, error is " + result);

            }
            logger.Debug("************end sendMail ************");
            return result;
        }