public void ImmediateReply(object item, SendCondition condition) { Microsoft.Office.Interop.Outlook.MailItem mailItem = item as Microsoft.Office.Interop.Outlook.MailItem; if (mailItem == null) { throw new Exception("ImmediateReply: mailItem is undefined."); } string body = CreateResponseBody(mailItem.Subject.ToLower(), mailItem.Sender.Name, condition); if (body == null) { return; } Microsoft.Office.Interop.Outlook.MailItem reply = mailItem.ReplyAll(); reply.HTMLBody = AdjustText(reply.HTMLBody); reply.HTMLBody = body + reply.HTMLBody; reply.Attachments.Add(this.attachmentFileName); if (condition == SendCondition.Conditional) { reply.Display(); } else { reply.Send(); } //mailItem.HTMLBody = string.Format( "<font size='1' color='red'><div id='replysent' > Reply sent on: {0}</div><font><br>", System.DateTime.Now.ToShortDateString() ) + mailItem.HTMLBody; //font-size:14px; font-family:Times New Roman; mailItem.HTMLBody = string.Format("<div id='replysent' style='color:darkblue; font-size:8px; font-family:Times New Roman;' > Reply sent on: {0}</div><br>", System.DateTime.Now.ToShortDateString()) + mailItem.HTMLBody; }
private string CreateResponseBody(string subject, string senderName, SendCondition condition) { //string senderName = sender.Name; //string senderAddress = sender.Address; string[] array = senderName.Split(' '); if (array.Length > 1) { senderName = array[0]; } else { array = senderName.Split('.'); if (array.Length > 1) { senderName = array[0]; } else { array = senderName.Split('-'); if (array.Length > 1) { senderName = array[0]; } else { array = senderName.Split('_'); if (array.Length > 1) { senderName = array[0]; } else { array = senderName.Split('@'); if (array.Length > 1) { senderName = array[0]; } } // } } // } IList <Entity> relevantRoles = new List <Entity>(); IList <Entity> irrelevantRoles = new List <Entity>(); IList <Entity> veryIrrelevantRoles = new List <Entity>(); foreach (Entity entity in roles) { if (isMatched(subject, entity.Item.ToLower())) //if (subject.Contains( entity.Item.ToLower() ) ) { if (entity.Attrib == 0) { veryIrrelevantRoles.Add(new Entity(entity.Item, entity.Attrib)); } else if (entity.Attrib == 1) { irrelevantRoles.Add(new Entity(entity.Item, entity.Attrib)); } else if (entity.Attrib == 2) { relevantRoles.Add(new Entity(entity.Item, entity.Attrib)); } else if (entity.Attrib == 4) { } else { throw new Exception("data error: " + entity.ToString()); } // } } bool proceed = false; if (relevantRoles.Count > 0 && condition == SendCondition.Conditional) { DialogResult result = MessageBox.Show("RelevantRole (" + relevantRoles[0].Item + ") found." + Environment.NewLine + Environment.NewLine + "Proceed?", "Proceed?", MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.No) { return(null); } proceed = true; // } else { //return null; if (condition == SendCondition.Conditional) { if ((irrelevantRoles.Count > 0) || (veryIrrelevantRoles.Count > 0)) { proceed = true; } else { DialogResult result = System.Windows.Forms.MessageBox.Show("Did not find an IrrelevantRole." + Environment.NewLine + Environment.NewLine + "Proceed?", "Proceed?", MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.No) { return(null); } proceed = true; // } // } else { proceed = true; } // } if (proceed) { string body = "<div style='font-size:14px; font-family:Times New Roman;'>" + this.outGoingMessage + "</div>"; System.Globalization.TextInfo myTI = new System.Globalization.CultureInfo("en-US", false).TextInfo; body = body.Replace("<person>", myTI.ToTitleCase(senderName)); if ((veryIrrelevantRoles.Count > 0)) { body = body.Replace("<veryirrelevant>", "But really...." + veryIrrelevantRoles[0].Item + "??"); } else { body = body.Replace("<veryirrelevant>", ""); } if (irrelevantRoles.Count > 0) { body = body.Replace("<role>", "(" + irrelevantRoles[0].Item + "s)"); } else if (veryIrrelevantRoles.Count > 0) { body = body.Replace("<role>", "(" + veryIrrelevantRoles[0].Item + "s)"); } else { body = body.Replace("<role>", ""); } return(body); // } return(null); // }