/// <summary> /// Send single mail /// </summary> /// <param name="databaseName">database Name</param> /// <param name="pid">Primary Key</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 databaseName, String pid, String fromName, String emailFrom, String emailTo, String emailSubject, String emailBody) { logger.Debug("************send Single Mail***************"); String result = OK_RESULT; try { if (String.IsNullOrEmpty(databaseName)) { return "No project Name"; } if (String.IsNullOrEmpty(pid)) { return "No primary Id"; } if (String.IsNullOrEmpty(emailFrom)) { return "No from Address"; } if (String.IsNullOrEmpty(emailTo)) { return "No to Address"; } ContactDatabaseAction contactDatabaseAction = new ContactDatabaseAction(client, userName, password, oWebProxy); String contactDatabaseId = contactDatabaseAction.createContactDatabase(databaseName); WorkspaceAction workspaceAction = new WorkspaceAction(client, userName, password, oWebProxy); String workspaceId = workspaceAction.createWorkspace(contactDatabaseId, databaseName); ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password, oWebProxy); Hashtable ht = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId); String toEmailFieldId; //Properties.Settings.Default.toEmailFieldId;// "MTExMzYxMTEfCGWCBaFKyA"; if (ht[EMAIL] != null) { toEmailFieldId = ht[EMAIL].ToString(); } else { return "Database:" + databaseName + " 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("yyyyMMddhhmmss"); // ContactGroupAction contactGroupAction = new ContactGroupAction(client, userName, password); //String contactGroupId = contactGroupAction.createContactGroup(contactDatabaseId, emailId, emailId); ContactAction contactAction = new ContactAction(client, userName, password, oWebProxy); ArrayList list = new ArrayList(); String jsonStr = PID + "#" + pid + "," + EMAIL + "#" + emailTo; list.Add(jsonStr); String contactId = contactAction.createContact(contactDatabaseId, list); DirectEmailTypeAction directEmailTypeAction = new DirectEmailTypeAction(client, userName, password, oWebProxy); String directEmailTypeId = directEmailTypeAction.createDirectEmailType(workspaceId, "Email Type for " + databaseName, "mail_type_" + databaseName, emailFrom, fromName, toEmailFieldId); DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy); String directEmailId = directEmailAction.createDirectEmail(directEmailTypeId, "Mail" + sequence, "mail" + sequence, emailSubject, "Send mail", fromName, emailFrom, emailBody); PublishingAction publishingAction = new PublishingAction(client, userName, password, oWebProxy); String publishId = publishingAction.publishTransactionalEmail(contactId, directEmailId,DateTime.Now); 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; }
/// <summary> /// send batch mail /// </summary> /// <param name="databaseName">databaseName</param> /// <param name="mailData">mailData</param> /// <returns></returns> public String sendBatchMail(String databaseName, MailData mailData) { logger.Debug("************send Batch Mail***************"); String result = OK_RESULT; try { if (String.IsNullOrEmpty(databaseName)) { return "No database Name"; } if (mailData == null || mailData.ContactJsonList == null || mailData.ContactJsonList.Count <= 0) { return "No Contact"; } ContactDatabaseAction contactDatabaseAction = new ContactDatabaseAction(client, userName, password, oWebProxy); String contactDatabaseId = contactDatabaseAction.createContactDatabase(databaseName); WorkspaceAction workspaceAction = new WorkspaceAction(client, userName, password, oWebProxy); String workspaceId = workspaceAction.createWorkspace(contactDatabaseId, databaseName); ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password, oWebProxy); Hashtable ht = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId); String toEmailFieldId; //Properties.Settings.Default.toEmailFieldId;// "MTExMzYxMTEfCGWCBaFKyA"; if (ht[EMAIL] != null) { toEmailFieldId = ht[EMAIL].ToString(); } else { return "Database:" + databaseName + " is not exist"; } const string pattern = "\\{.+?\\}"; List<string> tempList = Regex.Matches(mailData.mailBody, pattern).Cast<Match>().Select(a => a.Value).ToList(); foreach (string str in tempList) { mailData.mailBody = mailData.mailBody.Replace(str, str.ToLower()); } //查找<A的html标记,如果里面没有title属性,则增加这个属性. mailData.mailBody = Util.addTitleInAFlagHtml(mailData.mailBody); String sequence = DateTime.Now.ToString("yyyyMMddhhmmss"); ContactGroupAction contactGroupAction = new ContactGroupAction(client, userName, password, oWebProxy); // ContactGroup[] temp = contactGroupAction.getContactGroup(contactDatabaseId); String contactGroupId = contactGroupAction.createContactGroup(contactDatabaseId, "Mail Group" + sequence, "mail_group" + sequence); this.importContact(contactDatabaseId, contactGroupId, mailData); DirectEmailTypeAction directEmailTypeAction = new DirectEmailTypeAction(client, userName, password, oWebProxy); String directEmailTypeId = directEmailTypeAction.createDirectEmailType(workspaceId, "Email Type for" + databaseName, "mail_type_" + databaseName, mailData.fromAddress, mailData.sender, toEmailFieldId); DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy); String directEmailId = directEmailAction.createDirectEmail(directEmailTypeId, "Mail" + sequence, "mail" + sequence, mailData.subject, "Send mail", mailData.sender, mailData.fromAddress, mailData.mailBody); PublishingAction publishingAction = new PublishingAction(client, userName, password, oWebProxy); String publishId = publishingAction.publishingEmail(contactGroupId, directEmailId, DateTime.Now); 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; }