1

I try to read an email Internet headers that we can view it in email properties in outlook app I ask if there is an option so I can get this I use this code to read the emails in outlook

  Outlook::Application outlook;
  if (!outlook.isNull())
  {
  Outlook::NameSpace session(outlook.Session());
  session.Logon();
  Outlook::MAPIFolder *folder = session.GetDefaultFolder(Outlook::olFolderInbox);

  Outlook::Items* mails = new Outlook::Items(folder->Items());
  mails->Sort("ReceivedTime");
  int num = mails->Count();
  ui->label->setText(QString("I have %1 of messages").arg(QString::number(num)));

  // Indexing starts from 1
  for (int i = 1; i < num; i++)
  {
  Outlook::MailItem mail(mails->Item(i));
  QString s = mail.Subject(); // do something with subject
  QString b = mail.Body(); // do something with body
  ui->plainTextEdit->appendPlainText("subject : \n" + s);
  ui->plainTextEdit->appendPlainText("Body : " + b);
  ui->plainTextEdit->appendPlainText("-----------------------------------------------");
  }
  }

and I was check the Outlook::MailItem for a function to get this Internet header but I not found so if any one try it before or have any idea to solve this Thanks in advance

user7179690
  • 1,051
  • 3
  • 17
  • 40
  • I have 3 outlook profiles (3 different email accounts) setup. So how to choose which profile's (account's) Inbox to use? – user5155835 Nov 16 '17 at 08:23

1 Answers1

3

You can access the Internet headers via the PR_TRANSPORT_MESSAGE_HEADERS_W property. That property and other MAPI properties are retrievable via the PropertyAccessor object. Note though that individual x-headers are not accessible via a named MAPI property, they are bundled within the message headers so you'll need to parse every line of text to find any particular header record.

Eric Legault
  • 5,706
  • 2
  • 22
  • 38
  • I make the PropertyAccessor object from Outlook::MailItem what should I do then I try to use GetProperty("PR_TRANSPORT_MESSAGE_HEADERS_W ") but it give me invalid QVarint – user7179690 Mar 12 '17 at 08:59
  • 1
    Sorry, use the DASL name for that property: .GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F") – Eric Legault Mar 13 '17 at 00:20
  • please can you add the full part of the code to your answer Thank you – user7179690 Mar 13 '17 at 02:15
  • this what i try : Outlook::PropertyAccessor *acc = mail.PropertyAccessor(); QVariant var = acc->GetProperty("schemas.microsoft.com/mapi/proptag/0x007D001F"); – user7179690 Mar 13 '17 at 02:16
  • i got this error : QAxBase: Error calling IDispatch member GetProperty: Unknown error – user7179690 Mar 13 '17 at 02:17
  • Try 0x007D001E instead. Also see the documentation for GetProperty here, which very conveniently has a sample on getting the Internet headers: https://msdn.microsoft.com/en-us/library/ff868350.aspx – Eric Legault Mar 13 '17 at 19:36
  • I have 3 outlook profiles (3 different email accounts) setup. So how to choose which profile's (account's) Inbox to use? – user5155835 Nov 16 '17 at 08:22