나는이 코드 link을 사용하여 Outlook에서 전자 메일 헤더를 가져옵니다.현재 코드에서 컨텐트 유형의 전자 메일 머리글을 추출하지 않습니다
하지만 이메일 본문 (콘텐츠 유형)을 올바르게 추출하지 못합니다. 모든 것이 잘 작동합니다. 비교하고 싶다면 gmail을 열고 gmail 옵션을보고 헤더를 올바르게 보여주는 '원본보기'를 클릭하십시오.
위의 링크에서 코드를 제공 :
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Office.Interop.Outlook;
public static class MailItemExtensions
{
private const string HeaderRegex =
@"^(?<header_key>[-A-Za-z0-9]+)(?<seperator>:[ \t]*)" +
"(?<header_value>([^\r\n]|\r\n[ \t]+)*)(?<terminator>\r\n)";
private const string TransportMessageHeadersSchema =
"http://schemas.microsoft.com/mapi/proptag/0x007D001E";
public static string[] Headers(this MailItem mailItem, string name)
{
var headers = mailItem.HeaderLookup();
if (headers.Contains(name))
return headers[name].ToArray();
return new string[0];
}
public static ILookup<string, string> HeaderLookup(this MailItem mailItem)
{
var headerString = mailItem.HeaderString();
var headerMatches = Regex.Matches
(headerString, HeaderRegex, RegexOptions.Multiline).Cast<Match>();
return headerMatches.ToLookup(
h => h.Groups["header_key"].Value,
h => h.Groups["header_value"].Value);
}
public static string HeaderString(this MailItem mailItem)
{
return (string)mailItem.PropertyAccessor
.GetProperty(TransportMessageHeadersSchema);
}
}
출력 : Gmail의
MIME-Version: 1.0
Received: by someip with HTTP; Wed, 3 Dec 2014 10:04:00 -0800 (PST)
Date: Wed, 3 Dec 2014 23:34:00 +0530
Delivered-To: [email protected]
Message-ID: <[email protected]>
Subject: <subject here>
From: test name <test @gmail.com>
To: test name <test @gmail.com>
Content-Type: multipart/alternative; boundary=<somehash...>
출력 (Gmail의 메시지 옵션에서 '쇼 originl'를 클릭) :
MIME-Version: 1.0
Received: by someiphere with HTTP; Wed, 3 Dec 2014 10:04:00 -0800 (PST)
Date: Wed, 3 Dec 2014 23:34:00 +0530
Delivered-To: [email protected]
Message-ID: <[email protected]>
Subject: subjecthere
From: test name <[email protected]>
To: test name <[email protected]>
Content-Type: multipart/alternative; boundary=somehash
--somehash
Content-Type: text/plain; charset=UTF-8
messagehere
--somehash
Content-Type: text/html; charset=UTF-8
<div dir="ltr">messagehere</div>
--somehash--
당신은 당신의 코드를 단계별로 콘텐츠 유형을 얻기 위해 bellowing 코드를 사용한
다른 사람
위해 찾는? 정규 표현식이 맞습니까? 예를 들어 http://regexpad.com/#p-javascript와 같이 테스트 해 보셨습니까? 헤더에 실제로 "header_key"또는 "seperator> (sic)가 포함되어 있습니까? –mailitem.HeaderString()은 메일 본문을 제외한 전체 데이터를 반환합니다. 이는 메일 본문이 콘텐츠 유형 (gmail)으로 표시되고 몇 가지 새로운 라인, 그 코드에서 처리되지 않을 수 있습니다. 그건 그렇고 내 코드가 아니야, 어딘가에 온라인으로 봤다. 내가 regexpad에서 코드를 아직 테스트하지 않았어, 내가 시도합니다 – user2349115
나는 아웃룩뿐만 아니라 Gmail에서 출력을 추가 할 수 있도록 – user2349115