// _mailViewForm.SomeEvent += new EventHandler(this.HandleSomeEvent); //public void HandleSomeEvent(object sender, EventArgs e) //{ //} private void PopUpMail() { if (MailTab_Inbox) { if (gridviewMails.SelectedRows.Count > 0) { string FromMail = gridviewMails.SelectedRows[0].Cells["ColFrom"].Value.ToString(); string Subject = gridviewMails.SelectedRows[0].Cells["ColSubject"].Value.ToString(); string Msg = gridviewMails.SelectedRows[0].Cells["ColMsg"].Value.ToString(); int MsgId = (int)gridviewMails.SelectedRows[0].Cells["ColMsgId"].Value; string FileName = gridviewMails.SelectedRows[0].Cells["ColFileName"].Value.ToString(); MakeMailAsRead(); MailView _mailViewForm = new MailView(MsgId, false, FromMail, Subject, Msg, FileName, false); _mailViewForm.ShowDialog(); LoadInboxMails(); } } else if (MailTab_Draft) { if (gridviewMails.SelectedRows.Count > 0) { string FromMail = gridviewMails.SelectedRows[0].Cells["ColTo"].Value.ToString(); string Subject = gridviewMails.SelectedRows[0].Cells["ColSubject"].Value.ToString(); string Msg = gridviewMails.SelectedRows[0].Cells["ColMsg"].Value.ToString(); int MsgId = (int)gridviewMails.SelectedRows[0].Cells["ColMsgId"].Value; ComposeMail _composeMail = new ComposeMail(ComposeMail.Mailtype.DraftMail, FromMail, Subject, Msg, MsgId); _composeMail.ShowDialog(); } } else if (MailTab_SentMails) { if (gridviewMails.SelectedRows.Count > 0) { string FromMail = gridviewMails.SelectedRows[0].Cells["ColTo"].Value.ToString(); string Subject = gridviewMails.SelectedRows[0].Cells["ColSubject"].Value.ToString(); string Msg = gridviewMails.SelectedRows[0].Cells["ColMsg"].Value.ToString(); int MsgId = (int)gridviewMails.SelectedRows[0].Cells["ColMsgId"].Value; string FileName = gridviewMails.SelectedRows[0].Cells["ColFileName"].Value.ToString(); MailView _mailViewForm = new MailView(MsgId, true, FromMail, Subject, Msg, FileName, false); _mailViewForm.ShowDialog(); LoadSentMails(); } } else if (MailTab_Recycle) { this.Size = new System.Drawing.Size(1202, 757); } }
private void ForwardSelectedMessage() { try { // create a new mail message Outlook.MailItem ForwardingMessage = (Outlook.MailItem) this.Application.CreateItem(Outlook.OlItemType.olMailItem); // In case you want to implement the custom outlook form you have use following commented 2 lines of code //Outlook.MAPIFolder templateFolder = this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); //ForwardingMessage = (Outlook.MailItem)templateFolder.Items.Add("IPM.Note.OutlookCustomForm1"); // get the currently selected message (the message on which the user right-clicked) Outlook.MailItem SelectedMessage; SelectedMessage = (Outlook.MailItem) this.Application.ActiveExplorer().Selection[1]; var cf = this.Application.ActiveExplorer().CurrentFolder; Console.WriteLine(cf.Name); var n = this.Application.ActiveExplorer().CurrentFolder.Name; Console.WriteLine(n); //using (var f = new SelectContact(SelectedMessage)) //{ // f.ShowDialog(); //} var x = new MailView(SelectedMessage); x.ShowDialog(); return; if (SelectedMessage != null) { if (ForwardingMessage != null) { //Subject ForwardingMessage.Subject = "FW: " + SelectedMessage.Subject; #region Attahment // Get the count of Attachments int attachCount = SelectedMessage.Attachments.Count; if (attachCount > 0) { // loop through each attachment for (int idx = 1; idx <= attachCount; idx++) { string sysPath = System.IO.Path.GetTempPath(); if (!System.IO.Directory.Exists(sysPath + "~test")) { System.IO.Directory.CreateDirectory(sysPath + "~test"); } // get attached file and save in temp folder string strSourceFileName = sysPath + "~test\\" + SelectedMessage.Attachments[idx].FileName; SelectedMessage.Attachments[idx].SaveAsFile(strSourceFileName); string strDisplayName = "Attachment"; int intPosition = 1; int intAttachType = (int)Outlook.OlAttachmentType.olEmbeddeditem; // Add the current attachment ForwardingMessage.Attachments.Add(strSourceFileName, intAttachType, intPosition, strDisplayName); } } #endregion #region Body string strHeader = "<p><br><br>" + "-----Original Message-----" + "<br>"; strHeader += "From: " + SelectedMessage.SenderName + "<br>"; strHeader += "Sent: " + SelectedMessage.SentOn.ToString() + "<br>"; strHeader += "To: " + SelectedMessage.To + "<br>"; strHeader += "Subject: " + SelectedMessage.Subject + "<br><br>"; ForwardingMessage.HTMLBody = strHeader + GetTrimmedBodyText(SelectedMessage.HTMLBody); #endregion ForwardingMessage.Display(false); } } } catch (Exception ex) { if (ex.Message.ToLower().StartsWith("unable to cast com object")) { MessageBox.Show("This is not a valid message and it can not be sent.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("ForwardSelectedMessage - " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }