예제 #1
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_IMAP();
            string dstEmail = dataDir + "1234.eml";

            // Create a message
            Aspose.Email.Mail.MailMessage msg;
            msg = new Aspose.Email.Mail.MailMessage(
            "*****@*****.**",
            "*****@*****.**",
            "subject",
            "message"
            );

            //Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            //Specify host, username and password for your client
            client.Host = "imap.gmail.com";

            // Set username
            client.Username = "******";

            // Set password
            client.Password = "******";

            // Set the port to 993. This is the SSL port of IMAP server
            client.Port = 993;

            // Enable SSL
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                // Subscribe to the Inbox folder
                client.SelectFolder(ImapFolderInfo.InBox);
                client.SubscribeFolder(client.CurrentFolder.Name);

                // Append the newly created message
                client.AppendMessage(client.CurrentFolder.Name, msg);

                System.Console.WriteLine("New Message Added Successfully");

                //Disconnect to the remote IMAP server
                client.Disconnect();

            }
            catch (Exception ex)
            {
                System.Console.Write(Environment.NewLine + ex.ToString());
            }

            Console.WriteLine(Environment.NewLine + "Added new message on IMAP server.");
        }
예제 #2
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir  = RunExamples.GetDataDir_IMAP();
            string dstEmail = dataDir + "1234.eml";

            // Create a message
            Aspose.Email.Mail.MailMessage msg;
            msg = new Aspose.Email.Mail.MailMessage(
                "*****@*****.**",
                "*****@*****.**",
                "subject",
                "message"
                );

            //Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            //Specify host, username and password for your client
            client.Host = "imap.gmail.com";

            // Set username
            client.Username = "******";

            // Set password
            client.Password = "******";

            // Set the port to 993. This is the SSL port of IMAP server
            client.Port = 993;

            // Enable SSL
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                // Subscribe to the Inbox folder
                client.SelectFolder(ImapFolderInfo.InBox);
                client.SubscribeFolder(client.CurrentFolder.Name);

                // Append the newly created message
                client.AppendMessage(client.CurrentFolder.Name, msg);

                System.Console.WriteLine("New Message Added Successfully");

                //Disconnect to the remote IMAP server
                client.Disconnect();
            }
            catch (Exception ex)
            {
                System.Console.Write(Environment.NewLine + ex.ToString());
            }

            Console.WriteLine(Environment.NewLine + "Added new message on IMAP server.");
        }
        /// <summary>
        /// Converts an instance of Aspose.Email.Mail.MailMessage to Aspose.Words.Document class
        /// </summary>
        /// <param name="message"></param>
        /// <param name="includeAttachments"></param>
        /// <returns></returns>
        public static Aspose.Words.Document MailMessageToDocumentConverter(Aspose.Email.Mail.MailMessage message, bool includeAttachments)
        {
            MemoryStream msgStream = new MemoryStream();

            message.Save(msgStream, MailMessageSaveType.MHtmlFormat);
            msgStream.Position = 0;

            // Load the MHTML stream using Aspose.Words for .NET
            Document msgDocument = new Document(msgStream);

            return(msgDocument);
        }
예제 #4
0
        private static void MailToImage()
        {
            Aspose.Email.Mail.MailMessage msg = Aspose.Email.Mail.MailMessage.Load(@"C:\test.msg", MessageFormat.Msg);

            MemoryStream msgStream = new MemoryStream();

            msg.Save(msgStream, MailMessageSaveType.MHtmlFromat);
            msgStream.Position = 0;

            Document msgDocument = new Document(msgStream);

            msgDocument.Save(@"C:\Outlook-Aspose.jpeg", Aspose.Words.SaveFormat.Jpeg);
        }
        protected void Gridview_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            //Accessing BoundField Column
            string UniqueUri = MessagesGridView.DataKeys[MessagesGridView.SelectedIndex].Value.ToString();

            Aspose.Email.Mail.MailMessage message =
                MailHelper.Current.GetMailMessage(ViewState["SelectedFolderName"].ToString(), UniqueUri);

            // Add the unique uri of the message to viewstate
            ViewState["MessageUniqueUri"] = UniqueUri;

            // Set subject
            EmailView_Subject.Text = message.Subject;

            // Set From
            EmailView_FromName.Text    = message.From.DisplayName;
            EmailView_FromAddress.Text = "";
            // If Name is available, then show address in brackets
            if (message.From.DisplayName.Trim().Length > 0)
            {
                EmailView_FromAddress.Text = "&lt;" + message.From.Address + "&gt;";
            }
            else
            {
                EmailView_FromName.Text = message.From.Address;
            }

            // Set to
            EmailView_To.Text = "to ";
            int iTo = 0;

            foreach (MailAddress to in message.To)
            {
                if (iTo > 0)
                {
                    EmailView_To.Text += ", ";
                }

                // If it has display name, show in Name <*****@*****.**> format
                if (to.DisplayName.Trim().Length > 0)
                {
                    EmailView_To.Text += to.DisplayName + " &lt;" + to.Address + "&gt;";
                }
                else
                {
                    EmailView_To.Text += to.Address;
                }

                iTo++;
            }

            // Set send date
            EmailView_SentDate.Text = message.Date.ToString("dddd") + ", " + message.Date.ToString();

            // Set the HTML Body
            //EmailView_MessageBody.Text = message.HtmlBody;
            EmailBodyIframe.Attributes["srcdoc"] = message.HtmlBody;
            EmailBodyIframe.Attributes["onload"] = "resizeIframe('EmailBodyIframe');";

            // Set attachments
            List <MessageAttachment> attachments = new List <MessageAttachment>();

            foreach (Attachment att in message.Attachments)
            {
                attachments.Add(new MessageAttachment(att.Name));
            }
            RepeaterAttachments.DataSource = attachments;
            RepeaterAttachments.DataBind();

            // Hide the messages list
            EmailsListDiv.Visible = false;
            // Show the view message div
            EmailViewDiv.Visible = true;
            // Tick the checkbox
            CheckBox chkbox = MessagesGridView.SelectedRow.Cells[0].FindControl("SelectedCheckBox") as CheckBox;

            chkbox.Checked = true;
        }