Пример #1
0
        /// <summary>
        /// Send single mail
        /// </summary>
        /// <param name="projectName">projectName</param>
        /// <param name="emailId">emailId</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 projectName, String emailId, String fromName, String emailFrom, String emailTo, String emailSubject, String emailBody)
        {
            logger.Debug("************send Single Mail***************");
           // System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
            String result = OK_RESULT;
            try
            {
                if (String.IsNullOrEmpty(projectName))
                {
                    return "No project Name";
                }
                if (String.IsNullOrEmpty(emailId))
                {
                    return "No Email Id";
                }
                if (String.IsNullOrEmpty(emailFrom))
                {
                    return "No from Address";
                }
                if (String.IsNullOrEmpty(emailTo))
                {
                    return "No to Address";
                }
                ContactDatabaseAction contactDatabaseAction = new ContactDatabaseAction(client, userName, password);
                String contactDatabaseId = contactDatabaseAction.createContactDatabase(projectName);

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

                ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password);
                Hashtable ht = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId);
                String toEmailFieldId; //Properties.Settings.Default.toEmailFieldId;// "MTExMzYxMTEfCGWCBaFKyA";
                if (ht[EMAIL] != null)
                {
                    toEmailFieldId = ht[EMAIL].ToString();
                }
                else
                {
                    return "Database:" + projectName + " 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);

                Random Rdm = new Random();
                int iRdm = Rdm.Next(10000, 99999);

                String sequence = iRdm.ToString()+"_"+ DateTime.Now.ToString("yyyyMMddHHmmssfffffff") ;
               //  ContactGroupAction contactGroupAction = new ContactGroupAction(client, userName, password);
                //String contactGroupId = contactGroupAction.createContactGroup(contactDatabaseId, emailId, emailId);
                ContactAction contactAction = new ContactAction(client, userName, password);
                ArrayList list = new ArrayList();
                String jsonStr = EMAIL_ID + "#" + emailId + "," + EMAIL + "#" + emailTo + "," + FROMMAIL + "#" + emailFrom + "," + SUBJECT + "#" + emailSubject;
                list.Add(jsonStr);
                String contactId = contactAction.createContact(contactDatabaseId, list);

                DirectEmailTypeAction directEmailTypeAction = new DirectEmailTypeAction(client, userName, password);
                String directEmailTypeId = directEmailTypeAction.createDirectEmailType(workspaceId, "IPSOS Email Type for " + projectName, "ipsos_mail_type_" + projectName, emailFrom, fromName, toEmailFieldId);
            //    String directEmailTypeId = directEmailTypeAction.createDirectEmailType(workspaceId, emailId, emailId, emailFrom, fromName, toEmailFieldId);

                DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password);
                String directEmailId = directEmailAction.createDirectEmail(directEmailTypeId, "IPSOS Mail" + sequence, "ipsos_mail" + sequence, emailSubject, "Send mail by IPSOS", fromName, emailFrom, emailBody);
                //String directEmailId = directEmailAction.createDirectEmail(directEmailTypeId, emailId, emailId, 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;
        }
Пример #2
0
        /// <summary>
        /// send mail
        /// </summary>
        /// <param name="customerName">customerName</param>
        /// <param name="mailData">mailData</param>
        /// <returns></returns>
        public String sendMail(String customerName,MailData mailData)
        {
            logger.Debug("************sendMail***************");
          //  System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
            String result = OK_RESULT;
            try
            {
                if (String.IsNullOrEmpty(customerName))
                {
                    return "No customer Name";
                }
                if (mailData == null || mailData.ContactJsonList == null || mailData.ContactJsonList.Count <= 0)
                {
                    return "No Contact";
                }
               ContactDatabaseAction contactDatabaseAction = new ContactDatabaseAction(client,userName,password);
               String contactDatabaseId = contactDatabaseAction.createContactDatabase(customerName);


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

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

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

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


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

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

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

               String importId = this.importContact(contactDatabaseId, contactGroupId, mailData);
               int sleepCnt = 0;
               while (!this.getImportStatus(importId).Equals(cn.tripolis.dialogue.import.importStatus.ENDED.ToString()))
               {
                   if (sleepCnt > 10)
                   {
                       return "fail to import contacts";
                   }
                   System.Threading.Thread.Sleep(10000);
                   sleepCnt++;
               }

                DirectEmailTypeAction directEmailTypeAction = new DirectEmailTypeAction(client, userName, password);
                String directEmailTypeId = directEmailTypeAction.createDirectEmailType(workspaceId, "IPSOS Email Type for" + customerName, "ipsos_mail_type_" + customerName, mailData.FromAddress, mailData.SendName, toEmailFieldId);
                
                DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password);
                String directEmailId = directEmailAction.createDirectEmail(directEmailTypeId, "IPSOS Mail" + sequence, "ipsos_mail" + sequence, mailData.Subject, "Send mail by IPSOS", mailData.SendName, mailData.FromAddress, mailData.Content);
                
                PublishingAction publishingAction = new PublishingAction(client, userName, password);
                String publishId = publishingAction.publishingEmail(contactGroupId, directEmailId);

                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;
        }
Пример #3
0
        /// <summary>
        /// Send single mail
        /// </summary>
        /// <param name="projectName">projectName</param>
        /// <param name="emailId">emailId</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>       

        private String sendSingleEmail_Old(String projectName, String emailId, String fromName, String emailFrom, String emailTo, String emailSubject, String emailBody)
        {
            logger.Debug("************send Single Mail***************");
            String result = OK_RESULT;
            try
            {
                if (String.IsNullOrEmpty(projectName))
                {
                    return "No project Name";
                }
                if (String.IsNullOrEmpty(emailId))
                {
                    return "No Email Id";
                }
                ContactDatabaseAction contactDatabaseAction = new ContactDatabaseAction(client, userName, password);
                String contactDatabaseId = contactDatabaseAction.createContactDatabase(projectName);

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

                ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password);
                Hashtable ht = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId);
                String toEmailFieldId; //Properties.Settings.Default.toEmailFieldId;// "MTExMzYxMTEfCGWCBaFKyA";
                if (ht[EMAIL] != null)
                {
                    toEmailFieldId = ht[EMAIL].ToString();
                }
                else
                {
                    return "Database:" + projectName + " 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("yyyyMMddHHmmssffff");
                ContactGroupAction contactGroupAction = new ContactGroupAction(client, userName, password);
                String contactGroupId = contactGroupAction.createContactGroup(contactDatabaseId, emailId, emailId);

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

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


                cn.tripolis.dialogue.subscription.SubscriptionService subscriptionService = new cn.tripolis.dialogue.subscription.SubscriptionService();
                cn.tripolis.dialogue.subscription.AuthInfo subscriptionAuthInfo = new cn.tripolis.dialogue.subscription.AuthInfo
                {
                    client = client,
                    username = userName,
                    password = password
                };
                subscriptionService.authInfo = subscriptionAuthInfo;
                cn.tripolis.dialogue.subscription.subscribeContactRequest request = new cn.tripolis.dialogue.subscription.subscribeContactRequest();
                request.contactDatabase = new cn.tripolis.dialogue.subscription.IdNameModel();
                request.contactDatabase.id = contactDatabaseId;
                request.workspace = new cn.tripolis.dialogue.subscription.IdNameModel();
                request.workspace.id = workspaceId;

                request.contactFields = new cn.tripolis.dialogue.subscription.ContactFieldValue[2];
                cn.tripolis.dialogue.subscription.ContactFieldValue contactFieldValue = new cn.tripolis.dialogue.subscription.ContactFieldValue();
                contactFieldValue.name = EMAIL;
                contactFieldValue.value = emailTo;
                request.contactFields.SetValue(contactFieldValue, 0);

                contactFieldValue = new cn.tripolis.dialogue.subscription.ContactFieldValue();
                contactFieldValue.name = EMAIL_ID;
                contactFieldValue.value = emailId;
                request.contactFields.SetValue(contactFieldValue, 1);

                request.directEmail = new cn.tripolis.dialogue.subscription.IdNameModel();
                request.directEmail.id = directEmailId;

                request.ip = "127.0.0.1";

                request.contactGroupSubscriptions = new cn.tripolis.dialogue.subscription.ContactGroupSubscription[1];
                cn.tripolis.dialogue.subscription.ContactGroupSubscription contactGroupSubscription = new cn.tripolis.dialogue.subscription.ContactGroupSubscription();
                contactGroupSubscription.confirmed = true;
                contactGroupSubscription.contactGroup = new cn.tripolis.dialogue.subscription.IdNameModel();
                contactGroupSubscription.contactGroup.id = contactGroupId;
                request.contactGroupSubscriptions.SetValue(contactGroupSubscription, 0);

                subscriptionService.subscribeContact(request);
                //result = response.id;
            }
            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;
        }