Esempio n. 1
0
        static void Main(string[] args)
        {
            //log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
            //log.Debug("Enter initMenus()");

            String client = "IPSOS API";//Training";
            String userName = "******";//[email protected]";
            String password = "******";

            //String client = "Training";
            //String userName = "******";
            //String password = "******";            


            //String client = "51job";//Training";
            //String userName = "******";//[email protected]";
            //String password = "******";
     
            MailAdapter mailAdapter = new MailAdapter(client, userName, password);
            MailData mailData = new MailData
                {
                    FromAddress = "*****@*****.**",
                    ReplyAddress = "*****@*****.**",
                    SendName = "AnPing From .Net Platform",
                    Subject = "Test:Send mail to Vivi hotmail through .net platform",
                    Content = System.IO.File.ReadAllText("../../content.html")
                };

            // mailData.MailId = "123123sdfsdfsdfsdf2323";

            String contactJson = "email:[email protected]";
            mailData.ContactJsonList.Add(contactJson);

          //  mailAdapter.sendSingleEmail("IPSOS_BATCH", "a2b7e5ce-b179-40e2-9094-5a572f11bb3b", mailData.SendName, mailData.FromAddress, mailData.ReplyAddress, mailData.Subject, mailData.Content);
          
            //mailAdapter.sendMail("IPSOS_TEST", mailData);



            DateTime startTime = DateTime.Now.AddHours(-12);

            DateTime endTime = DateTime.Now;

            // DateTime startTime = DateTime.Parse("2014-05-06 10:00:00");

           // DateTime endTime =  DateTime.Parse("2014-05-07 10:00:00");
            mailAdapter.getFeedbackInfo("IPSOS_Batch", startTime, endTime);
            System.Console.ReadLine();
        }
Esempio n. 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;
        }
Esempio n. 3
0
        /// <summary>
        /// Import contact to database
        /// </summary>
        /// <param name="contactDatabaseId">contact database id</param>
        /// <param name="contactGroupId">contact group id</param>
        /// <param name="mailData">mail data</param>
        private String importContact(String contactDatabaseId, String contactGroupId, MailData mailData)
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug("importContact:contactDatabaseId=" + contactDatabaseId);
            }

            String result = OK_RESULT;
            ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password);
            Hashtable contactFieldTable = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId);

            cn.tripolis.dialogue.import.ImportContactsRequest request = new cn.tripolis.dialogue.import.ImportContactsRequest();
            try
            {
              
                //Prepare contact CSV
                StringBuilder sb = new StringBuilder();
                //String[] contactFieldNames = null;

                int index = 0;
                foreach (String contactList in mailData.ContactJsonList)
                {
                    String[] contactFields = contactList.Split(',');
                    //init the CSV header
                    if (index == 0)
                    {
                        // contactFieldNames = new String[contactFields.Length];
                        foreach (String field in contactFields)
                        {
                            String fielName = field.Split(new[] { "#" }, StringSplitOptions.None)[0];
                            //add contact filed to table
                            if (contactFieldTable != null && !contactFieldTable.ContainsKey(fielName.ToLower()))
                            {
                                contactDatabaseFieldAction.addContactField(contactDatabaseId, fielName, "");

                            }
                            sb.Append("\"").Append(fielName).Append("\"").Append(";");
                        }

                        if (contactFieldTable != null && !contactFieldTable.ContainsKey(FROMMAIL.ToLower()))
                        {
                            contactDatabaseFieldAction.addContactField(contactDatabaseId, FROMMAIL, "");

                        }
                        sb.Append("\"").Append(FROMMAIL).Append("\"").Append(";");

                        if (contactFieldTable != null && !contactFieldTable.ContainsKey(SUBJECT.ToLower()))
                        {
                            contactDatabaseFieldAction.addContactField(contactDatabaseId, SUBJECT, "");

                        }
                        sb.Append("\"").Append(SUBJECT).Append("\"").Append(";");

                        sb.Remove(sb.Length - 1, 1);
                        sb.Append("\n");
                    }
                    foreach (String field in contactFields)
                    {

                        sb.Append("\"").Append(field.Split(new[] { "#" }, StringSplitOptions.None)[1]).Append("\"").Append(";");

                    }
                    sb.Append("\"").Append(mailData.FromAddress).Append("\"").Append(";");
                    sb.Append("\"").Append(mailData.Subject).Append("\"").Append(";");

                    sb.Remove(sb.Length - 1, 1);

                    sb.Append("\n");
                    index++;
                }

                request.reportReceiverAddress = mailData.ReplyAddress;
                request.importMode = cn.tripolis.dialogue.import.importMode.SYNCHRONIZE_GROUP;
                request.contactGroupIds = new[] { contactGroupId };
                request.extension = cn.tripolis.dialogue.import.fileExtension.CSV;
                request.fileName = "Contacts.csv";
                request.importFile = System.Text.Encoding.UTF8.GetBytes(sb.ToString());//System.IO.File.ReadAllBytes("../../Contacts_new.csv");
                cn.tripolis.dialogue.import.ImportIDResponse response = importService.importContacts(request);
                result = response.importId;

            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("error happens in get contact database fields, error is" + ex.Detail.InnerXml);
                }
                throw new Exception(ex.Detail.InnerXml);
            }
            return result;
        }