public static void Run()
        {
            //ExStart:SetMAPIProperties
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook();

            // Create a sample Message
            MapiMessage mapiMsg = new MapiMessage("*****@*****.**", "*****@*****.**", "This is subject", "This is body");

            // Set multiple properties
            mapiMsg.SetProperty(new MapiProperty(MapiPropertyTag.PR_SENDER_ADDRTYPE_W, Encoding.Unicode.GetBytes("EX")));
            MapiRecipient recipientTo     = mapiMsg.Recipients[0];
            MapiProperty  propAddressType = new MapiProperty(MapiPropertyTag.PR_RECEIVED_BY_ADDRTYPE_W, Encoding.UTF8.GetBytes("MYFAX"));

            recipientTo.SetProperty(propAddressType);
            string       faxAddress       = "My Fax User@/FN=fax#/VN=voice#/CO=My Company/CI=Local";
            MapiProperty propEmailAddress = new MapiProperty(MapiPropertyTag.PR_RECEIVED_BY_EMAIL_ADDRESS_W, Encoding.UTF8.GetBytes(faxAddress));

            recipientTo.SetProperty(propEmailAddress);
            mapiMsg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT | MapiMessageFlags.MSGFLAG_FROMME);
            mapiMsg.SetProperty(new MapiProperty(MapiPropertyTag.PR_RTF_IN_SYNC, BitConverter.GetBytes((long)1)));

            // Set DateTime property
            MapiProperty modificationTime = new MapiProperty(MapiPropertyTag.PR_LAST_MODIFICATION_TIME, ConvertDateTime(new DateTime(2013, 9, 11)));

            mapiMsg.SetProperty(modificationTime);
            mapiMsg.Save(dataDir + "MapiProp_out.msg");
            //ExEnd:SetMAPIProperties
        }
예제 #2
0
        public static void Run()
        {
            //ExStart:ReadAndWritingOutlookTemplateFile
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook();

            // Load the Outlook template (OFT) file in MailMessage's instance
            MailMessage message = MailMessage.Load(dataDir + "sample.oft", new MsgLoadOptions());

            // Set the sender and recipients information
            string senderDisplayName     = "John";
            string senderEmailAddress    = "*****@*****.**";
            string recipientDisplayName  = "William";
            string recipientEmailAddress = "*****@*****.**";

            message.Sender = new MailAddress(senderEmailAddress, senderDisplayName);
            message.To.Add(new MailAddress(recipientEmailAddress, recipientDisplayName));
            message.HtmlBody = message.HtmlBody.Replace("DisplayName", "<b>" + recipientDisplayName + "</b>");

            // Set the name, location and time in email body
            string meetingLocation = "<u>" + "Hall 1, Convention Center, New York, USA" + "</u>";
            string meetingTime     = "<u>" + "Monday, June 28, 2010" + "</u>";

            message.HtmlBody = message.HtmlBody.Replace("MeetingPlace", meetingLocation);
            message.HtmlBody = message.HtmlBody.Replace("MeetingTime", meetingTime);

            // Save the message in MSG format and open in Office Outlook
            MapiMessage msg = MapiMessage.FromMailMessage(message);

            msg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);
            msg.Save(dataDir + "ReadAndWritingOutlookTemplateFile_out.msg");
            //ExEnd:ReadAndWritingOutlookTemplateFile
        }
        public static void Run()
        {
            // The path to the File directory.
            string dataDir  = RunExamples.GetDataDir_Email();
            string dstEmail = dataDir + "New-Draft.msg";

            // Create a new instance of MailMessage class
            MailMessage message = new MailMessage();

            // Set sender information
            message.From = "*****@*****.**";

            // Add recipients
            message.To.Add("*****@*****.**");
            message.To.Add("*****@*****.**");

            // Set subject of the message
            message.Subject = "New message created by Aspose.Email";

            // Set Html body of the message
            message.IsBodyHtml = true;
            message.HtmlBody   = "<b>This line is in bold.</b> <br/> <br/><font color=blue>This line is in blue color</font>";

            // Create an instance of MapiMessage and load the MailMessag instance into it
            MapiMessage mapiMsg = MapiMessage.FromMailMessage(message);

            // Set the MapiMessageFlags as UNSENT and FROMME
            mapiMsg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT | MapiMessageFlags.MSGFLAG_FROMME);

            // Save the MapiMessage to disk
            mapiMsg.Save(dstEmail);

            Console.WriteLine(Environment.NewLine + "Created draft MSG at " + dstEmail);
        }
        public static void Run()
        {
            //ExStart:SetMAPIProperties
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook();

            // Create a sample Message
            MapiMessage mapiMsg = new MapiMessage("*****@*****.**", "*****@*****.**", "This is subject", "This is body");

            // Set multiple properties
            mapiMsg.SetProperty(new MapiProperty(MapiPropertyTag.PR_SENDER_ADDRTYPE_W, Encoding.Unicode.GetBytes("EX")));
            MapiRecipient recipientTo = mapiMsg.Recipients[0];
            MapiProperty propAddressType = new MapiProperty(MapiPropertyTag.PR_RECEIVED_BY_ADDRTYPE_W, Encoding.UTF8.GetBytes("MYFAX"));
            recipientTo.SetProperty(propAddressType);
            string faxAddress = "My Fax User@/FN=fax#/VN=voice#/CO=My Company/CI=Local";
            MapiProperty propEmailAddress = new MapiProperty(MapiPropertyTag.PR_RECEIVED_BY_EMAIL_ADDRESS_W, Encoding.UTF8.GetBytes(faxAddress));
            recipientTo.SetProperty(propEmailAddress);
            mapiMsg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT | MapiMessageFlags.MSGFLAG_FROMME);
            mapiMsg.SetProperty(new MapiProperty(MapiPropertyTag.PR_RTF_IN_SYNC, BitConverter.GetBytes((long)1)));

            // Set DateTime property
            MapiProperty modificationTime = new MapiProperty(MapiPropertyTag.PR_LAST_MODIFICATION_TIME, ConvertDateTime(new DateTime(2013, 9, 11)));
            mapiMsg.SetProperty(modificationTime);
            mapiMsg.Save(dataDir + "MapiProp_out.msg");
            //ExEnd:SetMAPIProperties
        }
        private static MapiMessage CreateTestMessage(bool draft)
        {
            MapiMessage msg = new MapiMessage(
                "*****@*****.**",
                "*****@*****.**",
                "Flagged message",
                "Make it nice and short, but descriptive. The description may appear in search engines' search results pages...");

            if (!draft)
            {
                msg.SetMessageFlags(msg.Flags ^ MapiMessageFlags.MSGFLAG_UNSENT);
            }

            return(msg);
        }
        private static MapiMessage CreateTestMessage(bool draft)
        {
            MapiMessage msg = new MapiMessage(
            "*****@*****.**",
            "*****@*****.**",
            "Flagged message",
            "Make it nice and short, but descriptive. The description may appear in search engines' search results pages...");

            if (!draft)
            {
                msg.SetMessageFlags(msg.Flags ^ MapiMessageFlags.MSGFLAG_UNSENT);
            }

            return msg;
        }
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Outlook();

            // ExStart:SavingMessageInDraftStatus
            // Change properties of an existing MSG file
            string strExistingMsg = @"message.msg";

            // Load the existing file in MailMessage and Change the properties
            MailMessage msg = MailMessage.Load(dataDir + strExistingMsg, new MsgLoadOptions());

            msg.Subject  += "NEW SUBJECT (updated by Aspose.Email)";
            msg.HtmlBody += "NEW BODY (udpated by Aspose.Email)";

            // Create an instance of type MapiMessage from MailMessage, Set message flag to un-sent (draft status) and Save it
            MapiMessage mapiMsg = MapiMessage.FromMailMessage(msg);

            mapiMsg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);
            mapiMsg.Save(dataDir + "SavingMessageInDraftStatus_out.msg");
            // ExEnd:SavingMessageInDraftStatus
        }
예제 #8
0
        public static void Run()
        {
            // ExStart:SetFollowUpForRecipients
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook();

            MailMessage mailMsg = new MailMessage();

            mailMsg.Sender = "*****@*****.**";
            mailMsg.To     = "*****@*****.**";
            mailMsg.Body   = "This message will test if follow up options can be added to a new mapi message.";

            MapiMessage mapi = MapiMessage.FromMailMessage(mailMsg);

            mapi.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);  // Mark this message as draft

            DateTime dtReminderDate = new DateTime(2013, 5, 23, 16, 40, 0);

            // Add the follow up flag for receipient now
            FollowUpManager.SetFlagForRecipients(mapi, "Follow up", dtReminderDate);
            mapi.Save(dataDir + "SetFollowUpForRecipients_out.msg");
            // ExEnd:SetFollowUpForRecipients
        }
예제 #9
0
        private void genrateSampleTemplate()
        {
            string strFrom               = textBoxFrom.Text;
            string strTo                 = textBoxTo.Text;
            string strCC                 = textBoxCC.Text;
            string strSubject            = textBoxSubject.Text;
            string strTemplate           = textBoxTemplate.Text;
            string strWorkPath           = textBoxWorkPath.Text;
            string strPreProcessedFolder = textBoxPreProcessedFolder.Text;
            string strProcessedFolder    = textBoxProcessedFolder.Text;
            string strTestcasePrefix     = textBoxTestCasePrefix.Text;
            string strLogfilePrefix      = textBoxLogfilePrefix.Text;
            int    intKeepOpen           = StrToIntDef(textBoxKeepOpen.Text, 3);

            processTimeoutInSecond = StrToIntDef(textBoxProcessTimeout.Text, 10);

            textBoxKeepOpen.Text = intKeepOpen.ToString();
            Boolean isURLEncoded = checkBoxURLDecode.Checked;
            Boolean isAutoRun    = checkBoxAutoRun.Checked;

            timestampLogger = new TimestampLogging(strWorkPath + "\\" + strLogfilePrefix);
            payloadsProcessedTestcaseFilesLogger = new SimpleLogging(strWorkPath + "\\" + textBoxProcessedTestcaseFilesFilename.Text);
            //logger.log("==Begin==");

            // to kill it on timeout: http://stackoverflow.com/questions/1410602/how-do-set-a-timeout-for-a-method
            Action <object, string, string, string, int> longMethod_showCloseMoveEmail = showCloseMoveEmail;

            try
            {
                string strPreProcessedFolderFullPath = strWorkPath + "\\" + strPreProcessedFolder + "\\";
                string strProcessedFolderFullPath    = strWorkPath + "\\" + strProcessedFolder + "\\";
                System.IO.Directory.CreateDirectory(strPreProcessedFolderFullPath);
                System.IO.Directory.CreateDirectory(strProcessedFolderFullPath);

                if (isURLEncoded)
                {
                    timestampLogger.log("URL Decoding...");
                    strTemplate = Uri.UnescapeDataString(strTemplate);
                }

                MailMessage msg = new MailMessage();

                // Set recipients information
                if (!String.IsNullOrEmpty(strFrom))
                {
                    msg.From = strFrom;
                }
                if (!String.IsNullOrEmpty(strTo))
                {
                    msg.To = strTo;
                }
                if (!String.IsNullOrEmpty(strCC))
                {
                    msg.CC = strCC;
                }

                // Set the subject
                msg.Subject = strSubject;

                // Set HTML body
                msg.HtmlBody = strTemplate;

                // Add an attachment
                // msg.Attachments.Add(new Aspose.Email.Mail.Attachment("test.txt"));

                // Local filenames
                string strTestCaseFileName   = MakeValidFileName(strTestcasePrefix + strSubject + ".msg");
                string strInProgressFilePath = strPreProcessedFolderFullPath + strTestCaseFileName;

                //msg.Save(strFullFilePath,SaveOptions.DefaultMsg);

                MapiMessage outlookMsg = MapiMessage.FromMailMessage(msg);
                outlookMsg.SetMessageFlags(MapiMessageFlags.MSGFLAG_SUBMIT);


                while (File.Exists(strInProgressFilePath))
                {
                    strInProgressFilePath = strPreProcessedFolderFullPath + Guid.NewGuid() + "_" + strTestCaseFileName;
                }
                timestampLogger.log("Saving the " + strTestCaseFileName + " file in: " + strInProgressFilePath);
                outlookMsg.Save(strInProgressFilePath);

                if (isAutoRun)
                {
                    new Thread(delegate()
                    {
                        //showCloseMoveEmail(strInProgressFilePath, strProcessedFolderFullPath, strTestCaseFileName, intKeepOpen);

                        // to kill it on timeout: http://stackoverflow.com/questions/1410602/how-do-set-a-timeout-for-a-method
                        object monitorSync = new object();
                        bool timedOut;
                        lock (monitorSync)
                        {
                            longMethod_showCloseMoveEmail.BeginInvoke(monitorSync, strInProgressFilePath, strProcessedFolderFullPath, strTestCaseFileName, intKeepOpen, null, null);
                            timedOut = !Monitor.Wait(monitorSync, TimeSpan.FromSeconds(processTimeoutInSecond));
                        }
                        if (timedOut)
                        {
                            object _lock = new object();
                            lock (_lock)
                            {
                                killProcess("OUTLOOK", processTimeoutInSecond);
                                timestampLogger.log("Process killed due to " + processTimeoutInSecond.ToString() + " seconds timeout");
                            }
                        }
                    }).Start();
                }
            }
            catch (Exception e)
            {
                timestampLogger.log("Error in genrateSampleTemplate(): " + e.StackTrace);
            }
            //logger.log("==End==");
        }
예제 #10
0
        private void genrateSpecialTestCases()
        {
            string strFrom               = textBoxFrom.Text;
            string strTo                 = textBoxTo.Text;
            string strCC                 = textBoxCC.Text;
            string strSubject            = textBoxSubject.Text;
            string strTemplate           = textBoxTemplate.Text;
            string strWorkPath           = textBoxWorkPath.Text;
            string strPreProcessedFolder = textBoxPreProcessedFolder.Text;
            string strProcessedFolder    = textBoxProcessedFolder.Text;
            string strTestcasePrefix     = textBoxTestCasePrefix.Text;
            string strLogfilePrefix      = textBoxLogfilePrefix.Text;
            string strPayloadPattern     = textBoxPayloadPattern.Text;
            int    intKeepOpen           = StrToIntDef(textBoxKeepOpen.Text, 3);

            processTimeoutInSecond = StrToIntDef(textBoxProcessTimeout.Text, 10);
            textBoxKeepOpen.Text   = intKeepOpen.ToString();
            Boolean isURLEncoded = checkBoxURLDecode.Checked;
            Boolean isAutoRun    = checkBoxAutoRun.Checked;



            timestampLogger    = new TimestampLogging(strWorkPath + "\\" + strLogfilePrefix);
            payloadsListLogger = new SimpleLogging(strWorkPath + "\\" + textBoxPayloadsListFilename.Text);
            payloadsProcessedTestcaseFilesLogger = new SimpleLogging(strWorkPath + "\\" + textBoxProcessedTestcaseFilesFilename.Text);
            //logger.log("==Begin==");

            try
            {
                caseID = 0;
                string[] arrPrefix         = UniqueTextArrayFromFile(textBoxPrefix.Text);
                string[] arrSuffix         = UniqueTextArrayFromFile(textBoxSuffix.Text);
                string[] arrFormula        = UniqueTextArrayFromFile(textBoxFormula.Text);
                string[] arrSchemes        = UniqueTextArrayFromFile(textBoxSchemes.Text);
                string[] arrTargets        = UniqueTextArrayFromFile(textBoxTargets.Text);
                string[] arrSpecialFormula = UniqueTextArrayFromFile(textBoxSpecialFormula.Text);

                string strPreProcessedFolderFullPath = strWorkPath + "\\" + strPreProcessedFolder + "\\";
                string strProcessedFolderFullPath    = strWorkPath + "\\" + strProcessedFolder + "\\";
                System.IO.Directory.CreateDirectory(strPreProcessedFolderFullPath);
                System.IO.Directory.CreateDirectory(strProcessedFolderFullPath);

                if (isURLEncoded)
                {
                    timestampLogger.log("URL Decoding...");
                    strTemplate = Uri.UnescapeDataString(strTemplate);
                }

                string strTemplateSha1Sig = SHA1FromString(strTemplate);

                int intPrefixParalDegree         = StrToIntDef(textBoxThreadPrefixHigh.Text, 1);
                int intTargetsParalDegree        = StrToIntDef(textBoxThreadTargetsHigh.Text, 2);
                int intSpecialFormulaParalDegree = StrToIntDef(textBoxThreadSpecialFormulaHigh.Text, 5);
                int intSuffixParalDegree         = StrToIntDef(textBoxThreadSuffixHigh.Text, 1);
                if (isAutoRun)
                {
                    intPrefixParalDegree         = StrToIntDef(textBoxThreadPrefixLow.Text, 1);
                    intTargetsParalDegree        = StrToIntDef(textBoxThreadTargetsLow.Text, 1);
                    intSpecialFormulaParalDegree = StrToIntDef(textBoxThreadSpecialFormulaLow.Text, 3);
                    intSuffixParalDegree         = StrToIntDef(textBoxThreadSuffixLow.Text, 1);
                }

                long totalEvents = arrPrefix.Length * arrTargets.Length * arrSpecialFormula.Length * arrSuffix.Length;
                progressBarStatus.Value = 0;
                setLabelStatus(0, totalEvents);
                ResetCaseID();

                // to kill it on timeout: http://stackoverflow.com/questions/1410602/how-do-set-a-timeout-for-a-method
                Action <object, string, string, string, int> longMethod_showCloseMoveEmail = showCloseMoveEmail;

                Parallel.ForEach(arrPrefix, new ParallelOptions {
                    MaxDegreeOfParallelism = intPrefixParalDegree
                }, (strPrefix, loopStatePrefix) =>
                {
                    Parallel.ForEach(arrTargets, new ParallelOptions {
                        MaxDegreeOfParallelism = intTargetsParalDegree
                    }, (strTarget, loopStateTargets) =>
                    {
                        Parallel.ForEach(arrSpecialFormula, new ParallelOptions {
                            MaxDegreeOfParallelism = intSpecialFormulaParalDegree
                        }, (strSpecialFormula, loopSpecialFormula) =>
                        {
                            Parallel.ForEach(arrSuffix, new ParallelOptions {
                                MaxDegreeOfParallelism = intSuffixParalDegree
                            }, (strSuffix, loopStateSuffix) =>
                            {
                                if (Interlocked.Read(ref paused) == 1)
                                {
                                    mre.WaitOne();
                                }

                                long currentCaseID = GetNextValue();
                                string strPayload  = strSpecialFormula.Replace("<$target$>", strTarget);
                                strPayload         = strPrefix + strPayload + strSuffix + currentCaseID.ToString();
                                payloadsListLogger.log(strTemplateSha1Sig + "," + strPayload);

                                string strTempTemplate = System.Text.RegularExpressions.Regex.Replace(strTemplate, strPayloadPattern, strPayload);
                                string strTempSubject  = System.Text.RegularExpressions.Regex.Replace(strSubject, strPayloadPattern, strPayload);
                                string strTempFrom     = System.Text.RegularExpressions.Regex.Replace(strFrom, strPayloadPattern, strPayload);
                                string strTempTo       = System.Text.RegularExpressions.Regex.Replace(strTo, strPayloadPattern, strPayload);
                                string strTempCC       = System.Text.RegularExpressions.Regex.Replace(strCC, strPayloadPattern, strPayload);


                                MailMessage msg = new MailMessage();

                                // Set recipients information
                                if (!String.IsNullOrEmpty(strTempFrom))
                                {
                                    msg.From = strTempFrom;
                                }
                                if (!String.IsNullOrEmpty(strTempTo))
                                {
                                    msg.To = strTempTo;
                                }
                                if (!String.IsNullOrEmpty(strTempCC))
                                {
                                    msg.CC = strTempCC;
                                }

                                // Set the subject
                                msg.Subject = strTempSubject;

                                // Set HTML body
                                msg.HtmlBody = strTempTemplate;

                                // Add an attachment
                                // msg.Attachments.Add(new Aspose.Email.Mail.Attachment("test.txt"));

                                // Local filenames
                                string strTestCaseFileName   = MakeValidFileName(strTestcasePrefix + currentCaseID.ToString() + "-" + strTempSubject + ".msg");
                                string strInProgressFilePath = strPreProcessedFolderFullPath + strTestCaseFileName;

                                //msg.Save(strFullFilePath,SaveOptions.DefaultMsg);

                                MapiMessage outlookMsg = MapiMessage.FromMailMessage(msg);
                                outlookMsg.SetMessageFlags(MapiMessageFlags.MSGFLAG_SUBMIT);


                                while (File.Exists(strInProgressFilePath))
                                {
                                    strInProgressFilePath = strPreProcessedFolderFullPath + Guid.NewGuid() + "_" + strTestCaseFileName;
                                }
                                timestampLogger.log("Saving the " + strTestCaseFileName + " file in: " + strInProgressFilePath);
                                outlookMsg.Save(strInProgressFilePath);

                                if (isAutoRun)
                                {
                                    mre.WaitOne();
                                    //showCloseMoveEmail(strInProgressFilePath, strProcessedFolderFullPath, strTestCaseFileName, intKeepOpen);

                                    // to kill it on timeout: http://stackoverflow.com/questions/1410602/how-do-set-a-timeout-for-a-method
                                    object monitorSync = new object();
                                    bool timedOut;
                                    lock (monitorSync)
                                    {
                                        longMethod_showCloseMoveEmail.BeginInvoke(monitorSync, strInProgressFilePath, strProcessedFolderFullPath, strTestCaseFileName, intKeepOpen, null, null);
                                        timedOut = !Monitor.Wait(monitorSync, TimeSpan.FromSeconds(processTimeoutInSecond));
                                    }
                                    if (timedOut)
                                    {
                                        object _lock = new object();
                                        lock (_lock)
                                        {
                                            killProcess("OUTLOOK", processTimeoutInSecond);
                                            timestampLogger.log("Process killed due to " + processTimeoutInSecond.ToString() + " seconds timeout");
                                        }
                                    }


                                    if (currentCaseID % 10 == 0 || currentCaseID == totalEvents)
                                    {
                                        setLabelStatus(currentCaseID, totalEvents);
                                    }
                                }
                                else
                                {
                                    if (currentCaseID % 100 == 0 || currentCaseID == totalEvents)
                                    {
                                        setLabelStatus(currentCaseID, totalEvents);
                                    }
                                }
                            }
                                             );
                        }
                                         );
                    }
                                     );
                }

                                 );
            }
            catch (Exception e)
            {
                timestampLogger.log("Error in genrateSpecialTestCases(): " + e.StackTrace);
                MessageBox.Show("An error occured!", "Error!");
            }
            //logger.log("==End==");
        }