public List<Email> GetMail() { bool newOnly = Config["GetMailType"].Equals("NEW") ? true : false; List<Email> emails = new List<Email>(); Email email1 = new Email(); email1.Subject = "Test Body " + DateTime.Now; email1.Body = "Test Body " + DateTime.Now; email1.From = "*****@*****.**"; email1.To = "*****@*****.**"; CurrentMailAccessIndicator = MailAccessIndicator.MailFetched; String attachmentFileName = DateTime.Now.ToString("yyyyMMddHHMMss-") + "test.txt"; emails.Add(email1); TimeLastChecked = DateTime.Now; return emails; }
public List<Domain.Email> GetMail() { bool getAllMail = Config["GetMailType"].Equals("GETALLMAIL123")? true : false; List<Domain.Email> emails = new List<Domain.Email>(); try { using (LotusNotesMailClient client = new LotusNotesMailClient()) { LotusNotesMailService.Email[] emailsLotusNotes = client.GetMail(getAllMail); if (emailsLotusNotes != null) { CurrentMailAccessIndicator = MailAccessIndicator.MailChecked; foreach (var emailLotusNotes in emailsLotusNotes) { Domain.Email localEmail = new Domain.Email(); localEmail.From = emailLotusNotes.From; localEmail.To = emailLotusNotes.To; localEmail.Subject = emailLotusNotes.Subject; localEmail.Body = emailLotusNotes.Body; if (emailLotusNotes.Attachments != null && emailLotusNotes.Attachments.Length > 0) { try { using (LotusNotesMailClient clientFetchAttachments = new LotusNotesMailClient()) { emailLotusNotes.Attachments = clientFetchAttachments.GetEmailAttachments(emailLotusNotes); foreach (LotusNotesMailService.Attachment attachment in emailLotusNotes.Attachments) { Domain.Attachment localAttachment = new Domain.Attachment(); localAttachment.FileName = attachment.FileName; localAttachment.FilePath = attachment.FilePath; localAttachment.Content = attachment.Content; localEmail.Attachments.Add(localAttachment); } } } catch (Exception e) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Log(LogLevel.Error, "Exception occurred when getting attachments for the email", e); CurrentMailAccessIndicator = MailAccessIndicator.MailFetchError; } } emails.Add(localEmail); CurrentMailAccessIndicator = MailAccessIndicator.MailFetched; } } } } catch (CommunicationException ce) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Log(LogLevel.Error, "Exception occurred when connecting to the Lotus Notes mail server", ce); CurrentMailAccessIndicator = MailAccessIndicator.LoginError; } catch (Exception e) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Log(LogLevel.Error, "Exception occurred when retrieving mail from Lotus Notes", e); CurrentMailAccessIndicator = MailAccessIndicator.MailFetchError; } return emails; }
public List<Email> GetMail() { string getAllMail = Config["GetMailType"].Equals("GETALLMAIL123") ? "ALL" : "UNSEEN"; MessageCollection remoteEmails; List<Email> emails = new List<Email>(); ImapClient imapClient = new ImapClient(Config["Host_Google"], true, false); bool imapConnected = false; bool imapLoggedIn = false; try { imapConnected = imapClient.Connect(); imapLoggedIn = imapClient.Login(Config["User_Google"], Config["Password_Google"]); CurrentMailAccessIndicator = MailAccessIndicator.LoggedIn; } catch (Exception e) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Log(LogLevel.Error, "Connection to Google Mail server cannot be established.", e); } if (imapConnected && imapLoggedIn) { // Get messages from remote source ImapX.Folder InboxFolder = imapClient.Folders.Inbox; remoteEmails = InboxFolder.Messages; remoteEmails.Download(getAllMail); CurrentMailAccessIndicator = MailAccessIndicator.MailChecked; foreach (Message remoteEmail in remoteEmails) { try { Email email = new Email { Date = remoteEmail.Date, From = remoteEmail.From.Address.ToString(), Subject = remoteEmail.Subject, Body = remoteEmail.Body.Text }; if (remoteEmail.Attachments.Length > 0) { email.Attachments = new List<Domain.Attachment>(); foreach (ImapX.Attachment anAttachment in remoteEmail.Attachments) { anAttachment.Download(); string attachmentFileName = DateTime.Now.ToString("yyyyMMddHHMMss.f") + anAttachment.FileName; email.Attachments.Add( new Domain.Attachment { FileName = attachmentFileName, Content = anAttachment.FileData }); } } remoteEmail.Seen = Config["MarkAsSeen"].ToString().Equals("True") ? true : false; emails.Add(email); } catch (Exception e) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Log(LogLevel.Error, "Exception occurred when saving emails", e); CurrentMailAccessIndicator = MailAccessIndicator.MailFetchError; } CurrentMailAccessIndicator = MailAccessIndicator.MailFetched; } } imapClient.Dispose(); TimeLastChecked = DateTime.Now; return emails; }