public void DeleteMessagesOnServer(Message DefectEmail, string ProjectScope) { EmailSettings EmailSetting = new EmailSettings(); V1Logging Logs = new V1Logging(); V1XMLHelper V1XMLHelp = new V1XMLHelper(); string ToEmailAddress = V1XMLHelp.GetEmailAddressFromProjectScope(ProjectScope); try { EmailSetting = EmailSetting.GetEmailSettings(ToEmailAddress); // The client disconnects from the server when being disposed using (Pop3Client client = new Pop3Client()) { // Connect to the server client.Connect(EmailSetting.Pop3Server, EmailSetting.Pop3PortNumber, EmailSetting.UseSSLPop3); // Authenticate ourselves towards the server client.Authenticate(ToEmailAddress, EmailSetting.Password); if (client.Connected == true) { // Get the number of messages on the POP3 server int messageCount = client.GetMessageCount(); // Run trough each of these messages and download the headers for (int messageItem = messageCount; messageItem > 0; messageItem--) { // If the Message ID of the current message is the same as the parameter given, delete that message if (client.GetMessageHeaders(messageItem).MessageId == DefectEmail.Headers.MessageId) { // Delete client.DeleteMessage(messageItem); } } client.Disconnect(); } else { Logs.LogEvent("ERROR - Deleting Message - Can't connect to server to delete message."); } } } catch (Exception ex) { Logs.LogEvent("ERROR - Deleting Message - " + ex.ToString()); } }
public void CreateDefect(V1Connector CurrentV1Connection, List <Message> CurrentEmails) { V1XMLHelper V1XML = new V1XMLHelper(); V1Logging Logs = new V1Logging(); string ProjectScope = "Something for Testing"; string EmailBody; MessagePart MessageParts; SMTPResponse V1Response = new SMTPResponse(); MailChecker MailCheck = new MailChecker(); IServices services = new Services(CurrentV1Connection); try { foreach (Message MailItem in CurrentEmails) { for (int ToCtr = 0; ToCtr < MailItem.Headers.To.Count; ToCtr++) { ProjectScope = V1XML.GetProjectScope(MailItem.Headers.To[ToCtr].Address); if (ProjectScope != null) { Oid projectId = services.GetOid(ProjectScope); IAssetType defectType = services.Meta.GetAssetType("Defect"); Asset NewDefect = services.New(defectType, projectId); IAttributeDefinition nameAttribute = defectType.GetAttributeDefinition("Name"); NewDefect.SetAttributeValue(nameAttribute, MailItem.Headers.Subject.ToString()); MessageParts = MailItem.FindFirstHtmlVersion(); if (MessageParts == null) { MessageParts = MailItem.FindFirstPlainTextVersion(); } EmailBody = MessageParts.GetBodyAsText(); Logs.LogEvent("Operation - Creating Defect for " + MailItem.Headers.To[ToCtr].Address); IAttributeDefinition descriptionAttribute = defectType.GetAttributeDefinition("Description"); NewDefect.SetAttributeValue(descriptionAttribute, EmailBody); IAttributeDefinition FoundByAttribute = defectType.GetAttributeDefinition("FoundBy"); NewDefect.SetAttributeValue(FoundByAttribute, MailItem.Headers.From.ToString()); services.Save(NewDefect); IAttributeDefinition DefectIDAttribute = defectType.GetAttributeDefinition("Number"); Query IDQuery = new Query(NewDefect.Oid); IDQuery.Selection.Add(DefectIDAttribute); QueryResult ResultID = services.Retrieve(IDQuery); Asset defect = ResultID.Assets[0]; //NewDefect.GetAttribute(DefectIDAttribute).Value Logs.LogEvent("Operation - Sending Response to Defect Sender."); //Commented out the Response back to the Sender per John Waedekin //V1Response.SendResponse(MailItem, defect.GetAttribute(DefectIDAttribute).Value + " " + NewDefect.GetAttribute(nameAttribute).Value, ProjectScope); MailCheck.DeleteMessagesOnServer(MailItem, ProjectScope); } } } } catch (Exception ex) { Logs.LogEvent("ERROR - Creating Defect - " + ex.InnerException.Message); } }