コード例 #1
0
ファイル: Program.cs プロジェクト: booko365dev/BookExamples
        //gavdcodeend 05

        //gavdcodebegin 06
        static void ForwardEmail(ExchangeService ExService)
        {
            SearchFilter myFilter = new SearchFilter.SearchFilterCollection(
                LogicalOperator.And,
                new SearchFilter.IsEqualTo(
                    EmailMessageSchema.Subject,
                    "Email to forward"));
            ItemView myView = new ItemView(1);
            FindItemsResults <Item> findResults = ExService.FindItems(
                WellKnownFolderName.Inbox, myFilter, myView);

            ItemId myEmailId = null;

            foreach (Item oneItem in findResults)
            {
                myEmailId = oneItem.Id;
            }

            EmailMessage emailToReply = EmailMessage.Bind(ExService, myEmailId);

            EmailAddress[] forwardAddresses = new EmailAddress[1];
            forwardAddresses[0] = new EmailAddress("*****@*****.**");
            string myForward = "Forward body";

            emailToReply.Forward(myForward, forwardAddresses);
        }
コード例 #2
0
 /// <summary>
 /// Forward an E-mail, lets you introduce recipients.
 /// </summary>
 /// <param name="message">EMAILMESSAGE</param>
 /// <param name="index">Mail position on the treeview</param>
 /// <param name="service">EWS Service</param>
 /// <param name="addresses">List with the mail adresses that the user is forwarding to</param>
 public static void Forward(EmailMessage message, Int32 index, ExchangeService service, List<EmailAddress> addresses)
 {
     var forwardWorker = new BackgroundWorker();
     forwardWorker.DoWork += (sender, args) =>
     {
         message.Forward(message.Body.Text, addresses);
     };
     forwardWorker.RunWorkerCompleted += (sender, args) =>
     {
         if (args.Error != null)
             MessageBox.Show(args.Error.ToString());
         ReplyMail.GlobalAccess.Invoke(new Action(() =>
         {
             ReplyMail.GlobalAccess.mailSentPic.Visible = true;
             ReplyMail.GlobalAccess.MailSentTxt.Visible = true;
             ReplyMail.GlobalAccess.button2.Visible = true;
         }));
     };
     forwardWorker.RunWorkerAsync();            
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: Sidd710/tempRepo
        private static void ProcessEmailAsInvalid(EmailMessage email, string mailboxMonitorAddress, FolderId invalidMailFolderId)
        {
            //forward for debugging
            LoggingManager.WriteToLog("Processing Mail", "Forwarding with body", "Invalid");
            MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Invalid"));
            email.Forward(new MessageBody(BodyType.HTML, "INVALID?"), new EmailAddress[1] {
                mailboxMonitorAddress
            });

            LoggingManager.WriteToLog("Processing Mail", "Forwarded with body", "Invalid");
            MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Invalid"));

            email.IsRead = true;
            email.Update(ConflictResolutionMode.AlwaysOverwrite);
            LoggingManager.WriteToLog("Processing Mail", "Email marked as", "Unread");
            MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Marked as", "Unread"));

            //move mail to processed folder
            email.Move(invalidMailFolderId);

            LoggingManager.WriteToLog("Processing Mail", "Email moved to", "Invalid");
            MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email moved to", "Invalid"));
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Sidd710/tempRepo
        private static bool ProcessEmailAttachments(EmailMessage email, string mailboxMonitorAddress, FolderId moveMailFolderId, long savedMySQLMessageId)
        {
            if (email.Attachments.Count > 0)
            {
                foreach (var emailAttachment in email.Attachments.Where(a => a.Name.ToLower().EndsWith("lic")))
                {
                    if (emailAttachment is FileAttachment)
                    {
                        var emailFileAttachment = emailAttachment as FileAttachment;
                        emailFileAttachment.Load();
                        var utfDecodedContent = Encoding.UTF8.GetString(emailFileAttachment.Content);
                        if (utfDecodedContent.Contains("---"))
                        {
                            Atum.DAL.Managers.LoggingManager.WriteToLog("Processing Mail", "From", email.Sender.Address);
                            MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "From", email.Sender.Address));
                            Atum.DAL.Managers.LoggingManager.WriteToLog("Processing Mail", "Start of license block", "Found");
                            MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Start of license block", "Found"));

                            var activatedLicenseFile = Atum.DAL.Licenses.OnlineCatalogLicenses.FromLicenseStream(utfDecodedContent);

                            if (activatedLicenseFile.Count == 1)
                            {
                                LoggingManager.WriteToLog("Processing Mail", "License Object", "Processed");
                                MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "License Object", "Processed"));


                                //debug (use forwarding to monitor registration process)
                                email.Forward(new MessageBody(BodyType.HTML, "Done?"), new EmailAddress[1] {
                                    mailboxMonitorAddress
                                });
                                LoggingManager.WriteToLog("Processing Mail", "Forwarding with body", "Done");
                                MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Done"));

                                //prepare
                                var emailReply = new StringBuilder();
                                if (email.Body.BodyType == BodyType.HTML)
                                {
                                    emailReply.AppendLine("Dear customer, <br/><br/>Thank you for requesting an activation code.<br/><br/>");
                                }
                                else
                                {
                                    emailReply.AppendLine("Dear customer,");
                                    emailReply.AppendLine("Thank you for requesting an activation code.");
                                    emailReply.AppendLine();
                                    emailReply.AppendLine();
                                }

                                //activate license
                                activatedLicenseFile[0].Activated      = true;
                                activatedLicenseFile[0].ExpirationDate = DateTime.Now.AddYears(1);
                                activatedLicenseFile[0].ActivationDate = DateTime.Now;
                                activatedLicenseFile[0].LicenseType    = Atum.DAL.Licenses.AvailableLicense.TypeOfLicense.StudioStandard;

                                var emailFileAttachmentName          = emailFileAttachment.Name;
                                var emailFileAttachmentNameActivated = emailFileAttachment.Name.Substring(0, emailFileAttachment.Name.LastIndexOf("."));
                                emailFileAttachmentNameActivated += "-activated.lic";
                                var replyMessage = email.CreateReply(true);
                                replyMessage.BodyPrefix = emailReply.ToString();
                                EmailMessage replyEmailMessage = replyMessage.Save();
                                replyEmailMessage.Attachments.AddFileAttachment(emailFileAttachmentNameActivated, Encoding.UTF8.GetBytes(activatedLicenseFile.ToLicenseRequest()));
                                replyEmailMessage.Update(ConflictResolutionMode.AutoResolve);
                                replyEmailMessage.Send();

                                LoggingManager.WriteToLog("Processing Mail", "Forwarded with body", "Done");
                                MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Done"));

                                //mark as read
                                email.IsRead = true;
                                email.Update(ConflictResolutionMode.AlwaysOverwrite);
                                LoggingManager.WriteToLog("Processing Mail", "Email marked as", "Unread");
                                MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email marked as", "Unread"));

                                //save to database
                                MsSqlManager.UpdateRAWMessageWithActivationCode(savedMySQLMessageId, activatedLicenseFile);

                                //move mail to processed folder
                                email.Move(moveMailFolderId);
                                LoggingManager.WriteToLog("Processing Mail", "Email moved to", "Processed");
                                MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email moved to", "Processed"));

                                //save to path
                                var atumLicenseFile = new AtumEmailLicenseRequest(email.Sender.Address, email.DateTimeReceived, activatedLicenseFile[0]);
                                atumLicenseFile.Save();

                                LoggingManager.WriteToLog("Processing Mail", "Email moved to", "Processed");
                                MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email moved to", "Processed"));
                            }
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: Sidd710/tempRepo
        private static bool ProcessEmailBodyText(EmailMessage email, string mailboxMonitorAddress, FolderId moveMailFolderId, long savedMySQLMessageId)
        {
            if (email.Body.Text.Contains("---StartOfLicenseCode---"))
            {
                Atum.DAL.Managers.LoggingManager.WriteToLog("Processing Mail", "From", email.Sender.Address);
                Atum.DAL.Managers.LoggingManager.WriteToLog("Processing Mail", "Start of license block", "Found");

                var emailBodyAsHtml = email.Body.Text;
                var emailBodyText   = emailBodyAsHtml.Substring(emailBodyAsHtml.IndexOf("---StartOfLicenseCode---"));
                var endLicenseTag   = "---EndofLicenseCode---";
                emailBodyText = emailBodyText.Substring(0, emailBodyText.IndexOf(endLicenseTag) + endLicenseTag.Length);
                emailBodyText = Regex.Replace(emailBodyText, "<.*?>", string.Empty); //strip HTML tags
                emailBodyText = WebUtility.HtmlDecode(emailBodyText);                //convert html encoding to text encoding

                var licenseFile = Atum.DAL.Licenses.OnlineCatalogLicenses.FromLicenseStream(emailBodyText);

                if (licenseFile.Count == 1)
                {
                    LoggingManager.WriteToLog("Processing Mail", "License Object", "Processed");


                    //debug (use forwarding to monitor registration process)
                    email.Forward(new MessageBody(BodyType.HTML, "Done?"), new EmailAddress[1] {
                        mailboxMonitorAddress
                    });
                    MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Done"));
                    LoggingManager.WriteToLog("Processing Mail", "Forwarding with body", "Done");

                    //preprare
                    var emailReply = new StringBuilder();
                    if (email.Body.BodyType == BodyType.HTML)
                    {
                        emailReply.AppendLine("Dear customer, <br/><br/>Thank you for requesting an activation code.<br/><br/>");
                    }
                    else
                    {
                        emailReply.AppendLine("Dear customer,");
                        emailReply.AppendLine("Thank you for requesting an activation code.");
                        emailReply.AppendLine();
                        emailReply.AppendLine();
                    }

                    //activate license
                    licenseFile[0].Activated      = true;
                    licenseFile[0].ExpirationDate = DateTime.Now.AddYears(1);
                    licenseFile[0].ActivationDate = DateTime.Now;
                    licenseFile[0].LicenseType    = Atum.DAL.Licenses.AvailableLicense.TypeOfLicense.StudioStandard;

                    emailReply.AppendLine(licenseFile.ToLicenseRequest());
                    email.Reply(new MessageBody(email.Body.BodyType, emailReply.ToString()), true);

                    MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Done"));
                    LoggingManager.WriteToLog("Processing Mail", "Forwarded with body", "Done");

                    //mark as read
                    email.IsRead = true;
                    email.Update(ConflictResolutionMode.AlwaysOverwrite);
                    LoggingManager.WriteToLog("Processing Mail", "Email marked as", "Unread");
                    MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email marked as", "Unread"));

                    //save to database
                    MsSqlManager.UpdateRAWMessageWithActivationCode(savedMySQLMessageId, licenseFile);

                    //move mail to processed folder
                    email.Move(moveMailFolderId);
                    LoggingManager.WriteToLog("Processing Mail", "Email moved to", "Processed");
                    MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email moved to", "Processed"));

                    //save to path
                    var atumLicenseFile = new AtumEmailLicenseRequest(email.Sender.Address, email.DateTimeReceived, licenseFile[0]);
                    atumLicenseFile.Save();

                    LoggingManager.WriteToLog("Processing Mail", "Email moved to", "Processed");
                    MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email moved to", "Processed"));
                }
                return(true);
            }
            return(false);
        }