/// <summary> /// Send emails to multiple recipients by uploading a recipient list with a given deployment setup. /// </summary> public void SendMultipleEmailsWithGivenDeployment() { using (var em = new EMWebServicesClient(Auth.GetToken(), Settings.Default.EndPoint)) { string Token = Auth.GetToken(); // importSourceID, listID, deploymentID is prerequisite and can be set up in EM front-end UI. const int importSourceID = 21560; const int listID = 1192; const int deploymentID = 2563; // Put data to fit into field order as a CSV format. // For a welcome email scenario, it can be a simple email // In case high volume is expected, emails can be bundled in one import call. string dataToImport = string.Empty; dataToImport += "email,firstname"; dataToImport += "\r\n"; dataToImport += "[email protected],john"; dataToImport += "\r\n"; dataToImport += "[email protected],jane"; dataToImport += "\r\n"; // Step 1 - Create import context long fileSize = dataToImport.Length; var arrayOfAddToList = new ArrayOfInt { listID }; // To upload data without sending email, don't need to assign deploymentID. var arrayOfAddToDeployments = new ArrayOfInt { deploymentID }; int importID = em.ListImport.CreateImport( Token, "ABC Automation", importSourceID, fileSize, arrayOfAddToList, arrayOfAddToDeployments ); // Step 2 - upload data const int chunknumber = 1; em.ListImport.ImportDataS(Token, importID, chunknumber, dataToImport); // Step 3 - Let EM know uploading is done from front-end side so that EM server to start importing from back-end em.ListImport.FinishImport(Token, importID); // Step 4 - Import status check // This is optional step to confirm the import process. Use only when import record size is more than a few thousand records and the use case is not for a real time scenario. var importStatus = em.ListImport.GetImportStatus(Token, importID); } }
/// <summary> /// Login to Email Manager and get token /// </summary> /// <param name="id"></param> /// <param name="pass"></param> public static string Login(string id, string pass) { using (var em = new EMWebServicesClient("", Settings.Default.EndPoint)) { string newPassword = ""; var LoginResult = em.Authenticator.Authenticate(id, pass, newPassword, true, DateTime.Now, out _token); switch (LoginResult) { case DMLoginResult.DMLR_SUCCESS: return("Login successful."); case DMLoginResult.DMLR_LOGINEXPIRED: break; case DMLoginResult.DMLR_LOGININVALID: return("Invalid id or password"); case DMLoginResult.DMLR_LOGINDISABLED: break; case DMLoginResult.DMLR_MAXATTEMPTEXCEEDED: break; case DMLoginResult.DMLR_CLIENTDISABLED: break; case DMLoginResult.DMLR_LOGININUSE: break; case DMLoginResult.DMLR_SYSTEMDISABLED: break; case DMLoginResult.DMLR_NEWPWREQUIRED: break; case DMLoginResult.DMLR_NEWPWINVALID: break; case DMLoginResult.DMLR_UNKNOWN: break; default: return("Login was not successful."); } return("Login was not successful."); } }
/// <summary> /// Download the records of a Email Manager list /// </summary> public void Download() { var token = Auth.GetToken(); using (var em = new EMWebServicesClient(token, Settings.Default.EndPoint)) { // Set Variable int listID = 1192; // List id can be loaded from app.config, if already know it. int fieldPrimaryKey; // Get list fields (columns) DMListField[] fields = em.ListManager.GetListFields(token, listID, out fieldPrimaryKey); // Get list records DMCursor dmCursor = new DMCursor(); DMRecipientRecord[] dmRecords = em.ListManager.GetListRecords(token, listID, 999999, ref dmCursor, DMPreviewDirection.DMPD_FIRST); // Write the CSV file with the retrieve data WriteToCSVFile(fields, dmRecords); } }
/// <summary> /// Create email creative with HTML and TEXT template /// </summary> public void Create() { using (var em = new EMWebServicesClient(Auth.GetToken(), Settings.Default.EndPoint)) { //Find or create a folder called "Test" to store the campaign. var folders = em.EmService.GetFolders(em.Token).ToList(); int parentFolderID; if (folders.Exists(f => f.Name.Equals("Test"))) { parentFolderID = folders.Find(f => f.Name.Equals("Test")).ID; } else { parentFolderID = em.EmService.CreateFolder(em.Token, 0, "Test"); } //Create blank campaign in specified folder string campaignName = "API Demo Test Campaign"; string campaignDescription = "This is test campaign"; // Create campaign if not exist. int campaignID = em.EmService.GetDocumentsByName(em.Token, campaignName).FirstOrDefault()?.ID ?? 0; if (campaignID == 0) { campaignID = em.EmService.CreateCampaign(em.Token, campaignName, campaignDescription, parentFolderID, false, false, null, null); } //Wait until the campaign can be saved - i.e. if it is currently being edited bool canSave = false; while (!canSave) { canSave = em.EmService.CanSaveCampaign(em.Token, campaignID); } //Begin edit of the campaign int campaignSaveID = em.EmService.BeginCampaignSave(em.Token, campaignID); //Create a simple email content, from HTML and text stored in a file String creativeName = "Email"; String description = ""; EMDocumentType type = EMDocumentType.EMDT_Email; EMContent htmlContent = new EMContent { Content = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data\\template.html")), Encoding = "", Type = EMContentType.EMCT_HTML }; EMContent textContent = new EMContent { Content = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data\\template.txt")), Encoding = "", Type = EMContentType.EMCT_Text }; em.EmService.QueueCampaignCreativeCreation(em.Token, campaignSaveID, creativeName, description, type, false, false, htmlContent, textContent, true); em.EmService.CommitCampaignSave(em.Token, campaignSaveID); } }