コード例 #1
0
ファイル: DialogueService_V1.cs プロジェクト: ZhouAnPing/Mail
        /// <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;
        }
コード例 #2
0
ファイル: DialogueService_V1.cs プロジェクト: ZhouAnPing/Mail
        /// <summary>
        /// create direct email
        /// </summary>
        /// <param name="directEmailId">direct email type id</param>
        /// <param name="emailLabel">email label</param>
        /// <param name="emailName">email name</param>
        /// <param name="subject">subject</param>
        /// <param name="description">decription</param>
        /// <param name="fromName">sender name</param>
        /// <param name="fromAddress">from address</param>
        /// <param name="htmlSource">html source</param>
        /// <returns>direct email id</returns>
        public String createDirectEmail(String directEmailTypeId, String emailLabel, String emailName, String subject, String description, String fromName, String fromAddress, String htmlSource)
        {
            DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy);
            return directEmailAction.createDirectEmail(directEmailTypeId, emailLabel, emailName, subject, description, fromName, fromAddress, htmlSource);

        }
コード例 #3
0
ファイル: DialogueService_V1.cs プロジェクト: ZhouAnPing/Mail
        /// <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;
        }
コード例 #4
0
ファイル: DialogueService_V1.cs プロジェクト: ZhouAnPing/Mail
        /// <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;
        }
コード例 #5
0
ファイル: MailAdapter.cs プロジェクト: ZhouAnPing/Mail
        /// <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;
        }
コード例 #6
0
ファイル: MailAdapter.cs プロジェクト: ZhouAnPing/Mail
        /// <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;
        }
コード例 #7
0
        public void sendMail(String EmailName, String groupId, String contactDatabaseId, String workspaceId, String emailTypeId, String fromName,
            String fromAddress, String reportReceiverAddress,  String subject, String htmlSource)
        {

            logger.InfoFormat("Begin sending mail for email " + EmailName);           

            //send test mail           
            this.sendNotification(contactDatabaseId, workspaceId, emailTypeId, reportReceiverAddress, subject+"[测试,请确认]", htmlSource);
            logger.InfoFormat("send test mail for email " + EmailName + " successfully");
           
            //Create Email
            DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy);
            String emailId = directEmailAction.createDirectEmail(emailTypeId, EmailName, EmailName, subject, "", fromName, fromAddress, htmlSource);
            logger.InfoFormat("Create email " + EmailName +  " successfully");

             return;
            //Publish Email
            logger.InfoFormat("Begin sending email  " + EmailName );            
            PublishingAction publishingAction = new PublishingAction(client, userName, password, oWebProxy);
            DateTime scheduleAt = DateTime.Now.AddMinutes(15);
            String publishId = publishingAction.publishingEmail(groupId, emailId, scheduleAt);
            Thread.Sleep(5 * 1000);
            while (true)
            {               
                publishingAction = new PublishingAction(client, userName, password, oWebProxy);
                Job job = publishingAction.getPublishStatus(publishId);
                if (job.status.Contains("ENDED"))
                {                    
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Sending Report");
                    sb.AppendLine("jobName=" + job.jobName);
                    sb.AppendLine("contactDatabaseLabel=" + job.contactDatabaseLabel);
                    sb.AppendLine("workspaceLabel=" + job.workspaceLabel);
                    sb.AppendLine("contactGroupLabel=" + job.contactGroupLabel);
                    sb.AppendLine("channel=" + job.channel);
                    sb.AppendLine("requestedNumberOfSend=" + job.requestedNumberOfSend);
                    sb.AppendLine("numberOfSend=" + job.numberOfSend);
                    sb.AppendLine("numberOfSkipped=" + job.numberOfSkipped);
                    

                   // Console.WriteLine(sb.ToString());
                    logger.InfoFormat("finish sending mail  " + EmailName + ", the sending status  is " + job.status + ", sending report is " + sb.ToString());
                    this.sendNotification(contactDatabaseId, workspaceId, emailTypeId, reportReceiverAddress, EmailName + "_邮件发送报告", sb.ToString());
                  
                    break;
                }
                logger.InfoFormat("Checking the sending status, and current sending status is " + job.status.ToString() + " for email: " + EmailName);
                Thread.Sleep(60 * 1000);
            }
            logger.InfoFormat("finish sending mail for email:" + EmailName);
        }
コード例 #8
0
 public String sendNotification(String contactDatabaseId, String workspaceId, String emailTypeId, String emailAddress, String subject, String emailContent)
 {
     DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy);
     String emailId = directEmailAction.createDirectEmail(emailTypeId, "Notification", "notification", subject, "", "Tripolis Support", emailAddress, emailContent);
     SubscribeAction subscribeAction = new SubscribeAction(client, userName, password, oWebProxy);
     String contactId = subscribeAction.subscribeSingleEmail(contactDatabaseId, workspaceId, emailAddress, emailId);
     return contactId;
 }
コード例 #9
0
ファイル: ChinaUnionAdapter.cs プロジェクト: ZhouAnPing/Mail
        /// <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 contactDatabaseId, String workspaceId, String directEmailTypeId,String emailId, String fromName, String emailFrom, String emailTo,String agent_no, String emailSubject, String emailBody)
        {
            logger.Debug("************send Single Mail***************");
            String result = OK_RESULT;
            try
            {
               
                if (String.IsNullOrEmpty(emailFrom))
                {
                    return "No from Address";
                }
                if (String.IsNullOrEmpty(emailTo))
                {
                    return "No to Address";
                }
              

                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 = EMAIL + "#" + emailTo + ",agent_no#" + agent_no;
                list.Add(jsonStr);
                String contactId = contactAction.createContact(contactDatabaseId, list);

                String directEmailId = emailId;
                if (String.IsNullOrEmpty(emailId))
                {

                    DirectEmailAction directEmailAction = new DirectEmailAction(client, userName, password, oWebProxy);
                     directEmailId = directEmailAction.createDirectEmail(directEmailTypeId, "测试邮件" + sequence, "mail" + sequence, emailSubject, "测试邮件", fromName, emailFrom, emailBody);
                }
                PublishingAction publishingAction = new PublishingAction(client, userName, password, oWebProxy);
                String publishId = publishingAction.publishTransactionalEmail(contactId, directEmailId, DateTime.Now);

                logger.Debug("publishId=" + publishId);

                result = "OK:" + 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;
        }