public String publishingSmallScaleEmail(String apiKey, ContactFileInfo contactFileInfo, 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; 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.publishingSmallScaleEmail(dialogueSetting, contactGroup, contactFileInfo, directEmail); }
/// <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; }
/// <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> public String importContact(String contactDatabaseId, String contactGroupId, String reportReceiverAddress, ContactFileInfo importFiles) { if (logger.IsDebugEnabled) { logger.Debug("importContact:contactDatabaseId=" + contactDatabaseId); } String result = ""; ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password, oWebProxy); Hashtable contactFieldTable = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId); cn.tripolis.dialogue.import.ImportContactsRequest request = new cn.tripolis.dialogue.import.ImportContactsRequest(); try { importService.Timeout = System.Threading.Timeout.Infinite; request.reportReceiverAddress = reportReceiverAddress; request.importMode = cn.tripolis.dialogue.import.importMode.SYNCHRONIZE_GROUP; request.contactGroupIds = new[] { contactGroupId }; request.extension = importFiles.fileType;// cn.tripolis.dialogue.import.fileExtension.CSV; if (importFiles.fileType.Equals(fileExtension.CSV) && !importFiles.csvDilimiter.Equals(ContactFileInfo.DEFAULT_CSV_DELIMIT)) { string fileContent = Encoding.UTF8.GetString(importFiles.fileContent); string revisedContent = fileContent.Replace(importFiles.csvDilimiter, ContactFileInfo.DEFAULT_CSV_DELIMIT); importFiles.fileContent = Encoding.UTF8.GetBytes(revisedContent); } request.fileName = importFiles.filename; request.importFile = importFiles.fileContent;//System.IO.File.ReadAllBytes("../../Contacts_new.csv"); //importService..importContactsAsync() 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; }
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(); }