Пример #1
0
        public String publishingBulkEmail(String apiKey, String contactfileName, String fromName, String fromAddress, String subject, String reportReceiveAddress, String mailBody)
        {
            DialogueSettingDao DialogueSettingDao = new DialogueSettingDao();
            DialogueSettingBO DB_DialogueSetting = DialogueSettingDao.Get(apiKey);

            Authorization authorization = new Authorization();
            authorization.client = DB_DialogueSetting.client;
            authorization.username = DB_DialogueSetting.username;
            authorization.password = DB_DialogueSetting.password;

            DialogueSetting dialogueSetting = new DialogueSetting();
            dialogueSetting.contactDatabaseId = DB_DialogueSetting.contactDatabaseId;
            dialogueSetting.workspaceId = DB_DialogueSetting.workspaceId;
            dialogueSetting.emailTypeId = DB_DialogueSetting.emailTypeId;
            dialogueSetting.ftpAccountId = DB_DialogueSetting.ftpAccountId;

            String prefix = DB_DialogueSetting.prefix;

            String sequence = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
            ContactGroup contactGroup = new ContactGroup();
            contactGroup.groupLabel = prefix + sequence;
            contactGroup.groupName = prefix + sequence;

            DirectEmail directEmail = new DirectEmail();
            directEmail.emailLabel = prefix + sequence;
            directEmail.emailName = prefix + sequence;
            directEmail.subject = subject;
            directEmail.description = subject;
            directEmail.fromName = fromName;
            directEmail.fromAddress = fromAddress;
            if (String.IsNullOrEmpty(reportReceiveAddress))
            {
                directEmail.reportReceiveAddress = fromAddress;
            }
            else
            {
                directEmail.reportReceiveAddress = reportReceiveAddress;
            }
            directEmail.htmlContent = mailBody;

            

            DialogueService_new dialogueService_new = new DialogueService_new(authorization.client, authorization.username, authorization.password, null);
            return dialogueService_new.publishingBulkEmail(dialogueSetting, contactGroup, contactfileName, directEmail);
        }
Пример #2
0
        public String sendMail(String APIKey, String fromName, String fromEmail, String subject, string mailContent, String toEmail, DateTime scheduleTime)
        {
            if (!APIKey.Equals("MjU4MDI1ODCzAn45YUUpJw"))
            {
                throw new Exception("API认证失败,请确认你的APIkey是否正确.");
            }
            Authorization authorization = new Authorization();

            authorization.client = "Training";
            authorization.username = "******";
            authorization.password = "******";
            DialogueService_new dialogueService_new = new DialogueService_new(authorization.client, authorization.username, authorization.password, null);

            DialogueSetting dialogueSetting = new DialogueSetting();
            dialogueSetting.contactDatabaseId = "MjU4MDI1ODCzAn45YUUpJw";
            dialogueSetting.workspaceId = "MjAzNDIwMzTIkkBLrbUiiA";
            dialogueSetting.emailTypeId = "MTgwNTE4MDVA5rEBE89J_w";


            DirectEmail directEmail = new DirectEmail();
            String sequence = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
            directEmail.emailLabel = sequence;
            directEmail.emailName = sequence;
            directEmail.subject = subject;
            directEmail.description = subject;
            directEmail.fromName = fromName;
            directEmail.fromAddress = fromEmail;
            directEmail.reportReceiveAddress = fromEmail;
            directEmail.htmlContent = mailContent;
            directEmail.sheduleTime = scheduleTime;

            KeyValuePair[] ContactInfos = new KeyValuePair[1];

            KeyValuePair ContactInfo = new KeyValuePair();
            ContactInfo.key = "email";
            ContactInfo.value = toEmail;
            ContactInfos[0] = ContactInfo;

            return dialogueService_new.sendSingleEmail(dialogueSetting, directEmail, ContactInfos);
        }
Пример #3
0
        public String registerContact(String apiKey, KeyValuePair[] ContactInfos)
        {
            DialogueSettingDao DialogueSettingDao = new DialogueSettingDao();
            DialogueSettingBO DB_DialogueSetting = DialogueSettingDao.Get(apiKey);

            Authorization authorization = new Authorization();
            authorization.client = DB_DialogueSetting.client;
            authorization.username = DB_DialogueSetting.username;
            authorization.password = DB_DialogueSetting.password;

            DialogueSetting dialogueSetting = new DialogueSetting();
            dialogueSetting.contactDatabaseId = DB_DialogueSetting.contactDatabaseId;
            dialogueSetting.workspaceId = DB_DialogueSetting.workspaceId;
            dialogueSetting.directEmailId = DB_DialogueSetting.directEmailId;

            DialogueService_new dialogueService_new = new DialogueService_new(authorization.client, authorization.username, authorization.password, null);
            return dialogueService_new.registerContact(dialogueSetting, ContactInfos);
        }
Пример #4
0
        /// <summary>
        /// send Register email 
        /// </summary>
        /// <param name="dialogueSetting">Dialogue setting, such as database Id, workspaceId</param>        
        /// <param name="ContactInfos">parameters related with contact information, such as email Id.</param>
        /// <returns></returns>
        public String registerContact(DialogueSetting dialogueSetting, TripolisDialogueAdapter.BO.KeyValuePair[] ContactInfos)
        {

            logger.Debug(System.Environment.NewLine + "Begin Register Contact.");
            String result = "OK";
            try
            {

                String contactDatabaseId = dialogueSetting.contactDatabaseId;
                String workspaceId = dialogueSetting.workspaceId;
               // String emailTypeId = dialogueSetting.emailTypeId;
                String directEmailId = dialogueSetting.directEmailId;


              
                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[ContactInfos.Length];
                cn.tripolis.dialogue.subscription.ContactFieldValue contactFieldValue;
                int i = 0;
                foreach (TripolisDialogueAdapter.BO.KeyValuePair keyValuePair in ContactInfos)
                {
                    contactFieldValue = new cn.tripolis.dialogue.subscription.ContactFieldValue();
                    contactFieldValue.name = keyValuePair.key;
                    contactFieldValue.value = keyValuePair.value;
                    request.contactFields.SetValue(contactFieldValue, i++);
                }
                if (!string.IsNullOrEmpty(directEmailId))
                {
                    request.directEmail = new cn.tripolis.dialogue.subscription.IdNameModel();
                    request.directEmail.id = directEmailId;
                }
                request.ip = "127.0.0.1";

                cn.tripolis.dialogue.subscription.IDResponse response = subscriptionService.subscribeContact(request);

                String contactId = response.id;


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

            }
            logger.Debug("Finish register Contact. Contact Id is " + result);
            return result;
        }
Пример #5
0
        /// <summary>
        /// send single email 
        /// </summary>
        /// <param name="dialogueSetting">Dialogue setting, such as database Id, workspaceId</param>
        /// <param name="directEmail">parameters related with direct email, such as subject, fromaddress</param>
        /// <param name="ContactInfos">parameters related with contact information, such as email Id.</param>
        /// <returns></returns>
        public String sendSingleEmail(DialogueSetting dialogueSetting, DirectEmail directEmail, TripolisDialogueAdapter.BO.KeyValuePair[] ContactInfos)
        {

            logger.Debug(System.Environment.NewLine + "Begin sending Single Email.");
            String result = "OK";
            try
            {

                String contactDatabaseId = dialogueSetting.contactDatabaseId;
                String workspaceId = dialogueSetting.workspaceId;
                String emailTypeId = dialogueSetting.emailTypeId;
                String directEmailId = dialogueSetting.directEmailId;


                //查找<A的html标记,如果里面没有title属性,则增加这个属性.
                directEmail.htmlContent = Util.addTitleInAFlagHtml(directEmail.htmlContent);

                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[ContactInfos.Length];
                cn.tripolis.dialogue.subscription.ContactFieldValue contactFieldValue;
                int i = 0;
                foreach (TripolisDialogueAdapter.BO.KeyValuePair keyValuePair in ContactInfos)
                {
                    contactFieldValue = new cn.tripolis.dialogue.subscription.ContactFieldValue();
                    contactFieldValue.name = keyValuePair.key;
                    contactFieldValue.value = keyValuePair.value;
                    request.contactFields.SetValue(contactFieldValue, i++);
                }

                request.ip = "127.0.0.1";

                cn.tripolis.dialogue.subscription.IDResponse response = subscriptionService.subscribeContact(request);

                String contactId = response.id;

                DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy);
                directEmailId = directEmailAction.createDirectEmail(emailTypeId, directEmail.emailLabel, directEmail.emailName, directEmail.subject, directEmail.description, directEmail.fromName, directEmail.fromAddress, directEmail.htmlContent);
                // directEmailAction.updateDirectEmail(directEmailId, directEmail.subject, directEmail.fromName, directEmail.htmlContent);

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


                //  SendLogDao dbAccess = new SendLogDao();
                //  dbAccess.SengLog_InsertInfo(new String[] { emailId, publishId, batchNo });
                result = publishId;
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                result = ex.Message;
                logger.Debug("error happen in send mail, error is " + result);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                logger.Debug("error happen in send mail, error is " + result);
                // return ex.Message;

            }
            logger.Debug("Finish sending Single Email. Publish Id is " + result);
            return result;
        }
Пример #6
0
        /// <summary>
        /// publish Small Scale email,, mail quantity <50,000
        /// </summary>
        /// <param name="dialogueSetting">Dialogue setting, such as database Id, workspaceId</param>
        /// <param name="contactGroup">Contact Group information</param>
        /// <param name="contacts">Contact Information</param>
        /// <param name="directEmail">parameters related with direct email, such as subject, fromaddress</param>
        /// <returns></returns>
        public String publishingSmallScaleEmail(DialogueSetting dialogueSetting, ContactGroup contactGroup, ContactFileInfo importFiles, DirectEmail directEmail)
        {

            logger.Debug(System.Environment.NewLine+"Begin sending Small Scale Email.");
            String result = "OK";
            try
            {
                String contactDatabaseId = dialogueSetting.contactDatabaseId;
                String workspaceId = dialogueSetting.workspaceId;
                String emailTypeId = dialogueSetting.emailTypeId;
                //String directEmailId = dialogueSetting.directEmailId;

                ContactGroupAction contactGroupAction = new ContactGroupAction(client, userName, password, oWebProxy);
                String contactGroupId = contactGroupAction.createContactGroup(contactDatabaseId, contactGroup.groupLabel, contactGroup.groupName);

                String importId = this.importContact(contactDatabaseId, contactGroupId, directEmail.reportReceiveAddress, importFiles);              

                DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy);
                String directEmailId = directEmailAction.createDirectEmail(emailTypeId, directEmail.emailLabel, directEmail.emailName, directEmail.subject, directEmail.description, directEmail.fromName, directEmail.fromAddress, directEmail.htmlContent);


                PublishingAction publishingAction = new PublishingAction(client, userName, password, oWebProxy);
                String publishId = publishingAction.publishingEmail(contactGroupId, directEmailId, DateTime.Now);
                result = publishId;
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                result = ex.Message;
                logger.Debug("error happen in sending Small Scale mail, error is " + result);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                logger.Debug("error happen in sending Small Scale mail, error is " + result);
                // return ex.Message;

            }
            logger.Debug("Finish sending Small Scale Email. Publish Id is " + result);
            return result;
        }
Пример #7
0
        /// <summary>
        /// publish Small Scale email, mail quantity >=50,000
        /// </summary>
        /// <param name="dialogueSetting">Dialogue setting, such as database Id, workspaceId</param>
        /// <param name="contactGroup">Contact Group information</param>
        /// <param name="contacts">Contact Information</param>
        /// <param name="directEmail">parameters related with direct email, such as subject, fromaddress</param>
        /// <returns></returns>
        public String publishingBulkEmail(DialogueSetting dialogueSetting, ContactGroup contactGroup, String fileName, DirectEmail directEmail)
        {

            logger.Debug(System.Environment.NewLine+"Begin sending Bulk Scale Email.");
            String result = "OK";
            try
            {
                String contactDatabaseId = dialogueSetting.contactDatabaseId;
                String workspaceId = dialogueSetting.workspaceId;
                String emailTypeId = dialogueSetting.emailTypeId;
              //  String directEmailId = "";

                ContactGroupAction contactGroupAction = new ContactGroupAction(client, userName, password, oWebProxy);
                String contactGroupId = contactGroupAction.createContactGroup(contactDatabaseId, contactGroup.groupLabel, contactGroup.groupName);

                DateTime scheduleAt = DateTime.Now;
                ImportContactAction importContactAction = new ImportContactAction(client, userName, password, oWebProxy);
                String importId = importContactAction.importContactFromFTP(contactDatabaseId, contactGroupId, fileName, directEmail.reportReceiveAddress, dialogueSetting.ftpAccountId, scheduleAt);
                Thread.Sleep(5 * 1000);
                while (true)
                {
                    importContactAction = new ImportContactAction(client, userName, password, oWebProxy);
                    importStatus status = importContactAction.getImportStatus(importId);

                    if (status.Equals(importStatus.ENDED))
                    {
                        logger.InfoFormat("import contact File " + fileName + " successfully");
                        break;
                    }
                    if (status.Equals(importStatus.STOPPED) || status.Equals(importStatus.ABORTED))
                    {
                        logger.InfoFormat("fail to import contact File " + fileName  + " as import status is " + status.ToString());
                        // throw new Exception("fail to import contact File " + fileName + " for transid " + transId + " as import status is " + status.ToString());
                        return "";
                        //break;
                    }
                    logger.InfoFormat("Checking the import status, and current import status is " + status.ToString() );
                    Thread.Sleep(60 * 1000);
                }
                DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy);
                String directEmailId = directEmailAction.createDirectEmail(emailTypeId, directEmail.emailLabel, directEmail.emailName, directEmail.subject, directEmail.description, directEmail.fromName, directEmail.fromAddress, directEmail.htmlContent);


                PublishingAction publishingAction = new PublishingAction(client, userName, password, oWebProxy);
                String publishId = publishingAction.publishingEmail(contactGroupId, directEmailId, DateTime.Now);
                result = publishId;
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                result = ex.Message;
                logger.Debug("error happen in sending Small Scale mail, error is " + result);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                logger.Debug("error happen in sending Small Scale mail, error is " + result);
                // return ex.Message;

            }
            logger.Debug("Finish sending Small Scale Email. Publish Id is " + result);
            return result;
        }
Пример #8
0
        static void Main(string[] args)
        {
            //String client = "IPSOS API";//Training";
            //String userName = "******";//[email protected]";
            //String password = "******";
            //String databaseID = "MjUyMTI1MjHJ69MSWqS6mQ";
            //String ftpAccountId = "NTQwNTQwNTQQosYwP6thgg";

            String client = "Training";
            String userName = "******";
            String password = "******";
           // String databaseID = "MjU4MDI1ODCzAn45YUUpJw";//"MjU1MTI1NTFFUVus6S83qA";


            //String client = "51job";
            //String userName = "******";
            //String password = "******";
            //String databaseID = "MjU1ODI1NTgL21MIxlZDCQ";
            //String ftpAccountId = "NTM4NTM4NTMEfaWC25Hk0Q";
            DialogueService_new dialogueService = new DialogueService_new(client, userName, password, null);

            //String mailJobId = "MTA0ODQyOTKMdCDprzC_oRpaAAO2LvZr";
            //String databaseID = "MjU1ODI1NTgL21MIxlZDCQ";
          

            DateTime startTime = DateTime.Now.AddDays(-1);
            DateTime endTime = DateTime.Now;

          
           //dialogueService.exportReportToFtp(databaseID,ftpAccountId, startTime, endTime,ReportType.SENT);

           ReportData mailReport =  dialogueService.getRerportByJobId("MTA1MzU3NDKMdCDprzC_oRpaAAO2LvZr", startTime, endTime);
            

            Console.WriteLine("Sent**********************");
            Console.WriteLine(mailReport.sent);

            Console.WriteLine("opened**********************");
            Console.WriteLine(mailReport.opened);

            Console.WriteLine("clicked**********************");
            Console.WriteLine(mailReport.clicked);

            Console.WriteLine("bounced**********************");
            Console.WriteLine(mailReport.bounced);

            Console.ReadLine();
           


            DialogueSetting dialogueSetting = new DialogueSetting();
            dialogueSetting.contactDatabaseId = "MjU1MTI1NTFFUVus6S83qA";
            dialogueSetting.workspaceId = "MjAwNzIwMDdKRmT4g3bWOg";
            dialogueSetting.emailTypeId = "MTc2MDE3NjBcUp_pC*h71w";
            
            DirectEmail directEmail = new DirectEmail();
            String sequence = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
            directEmail.emailLabel = sequence;
            directEmail.emailName = sequence;
            directEmail.subject = "单个邮件测试";
            directEmail.description = "API邮件测试";
            directEmail.fromName = "周安平";
            directEmail.fromAddress = "*****@*****.**";
            directEmail.reportReceiveAddress = "*****@*****.**";
            directEmail.htmlContent = "Hello World";

            KeyValuePair[] ContactInfos = new KeyValuePair[3];

            KeyValuePair ContactInfo = new KeyValuePair();
            ContactInfo.key = "email";
            ContactInfo.value = "*****@*****.**";
            ContactInfos[0] = ContactInfo;
            ContactInfo = new KeyValuePair();
            ContactInfo.key = "username";
            ContactInfo.value = "周安平";
            ContactInfos[1] = ContactInfo;
            ContactInfo = new KeyValuePair();
            ContactInfo.key = "password";
            ContactInfo.value = "12234234";
            ContactInfos[2] = ContactInfo;
            directEmail.subject = "单个邮件测试";
            dialogueService.sendSingleEmail(dialogueSetting, directEmail, ContactInfos);

            dialogueSetting.directEmailId = "MzczMDk1Mzc98HDFHcJFcg";
            directEmail.subject = "注册邮件测试";
            dialogueService.registerContact(dialogueSetting, ContactInfos);


            ContactGroup contactGroup = new ContactGroup();
            contactGroup.groupLabel = "Demo Group";
            contactGroup.groupName = "demogroup1";

            ContactFileInfo importFiles = new ContactFileInfo();
            importFiles.fileType = cn.tripolis.dialogue.import.fileExtension.CSV;
            importFiles.filename = "Contacts.csv";
            importFiles.csvDilimiter = ContactFileInfo.DEFAULT_CSV_DELIMIT;
            importFiles.fileContent = System.IO.File.ReadAllBytes("../../Example/Contacts.csv");
            directEmail.subject = "小批量邮件测试";
            dialogueService.publishingSmallScaleEmail(dialogueSetting, contactGroup, importFiles, directEmail);


            dialogueSetting.ftpAccountId = "NTM5NTM5NTNW_uqPXJDMzQ";
            directEmail.subject = "大批量邮件测试";
            dialogueService.publishingBulkEmail(dialogueSetting, contactGroup, "Contacts.xls", directEmail);

            System.Console.WriteLine("Finish Action");
            System.Console.ReadLine();
        }