Get read-receipt with MailKit with Microsoft anti-spam enabled - c#

I'm connecting to Office 365 mail servers using IMAP.
Our sysadmin enabled the anti-spam, so any recieved mail from outside is transformed: we just recieve a forward message rather that the original message.
With Thunderbird or Outlook Web Access, I can see the original mail as an attached EML file.
But when I try to parse attachements in the mails, I can't find attachement in those mails. If I recieve an email with a real attachement, I get can find it as attachement.
I tried a message.ToString() to get the complete message I recieve:
Received: from *****.prod.outlook.com (*****)
by *****.prod.outlook.com with HTTPS; Thu, 11 Aug 2022
13:37:42 +0000
Received: from *****.PROD.OUTLOOK.COM (*****) by
*****.prod.outlook.com (*****) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.23; Thu, 11 Aug
2022 13:37:41 +0000
Received: from *****.prod.protection.outlook.com
(*****) by *****.outlook.office365.com
(*****) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11 via Frontend
Transport; Thu, 11 Aug 2022 13:37:41 +0000
Authentication-Results: spf=none (sender IP is *****)
smtp.helo=*****.aznetwork.eu; dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=aznetwork.eu;compauth=pass
reason=105
Received-SPF: None (protection.outlook.com: *****.aznetwork.eu does not
designate permitted sender hosts)
Received: from *****.aznetwork.eu (*****) by
*****.mail.protection.outlook.com (*****) with Microsoft SMTP
Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
15.20.5525.11 via Frontend Transport; Thu, 11 Aug 2022 13:37:41 +0000
Received: from localhost (localhost.localdomain [127.0.0.1])
by *****.aznetwork.eu (Postfix) with ESMTP id 053BC1C631E
for <recipient#mail.com>; Thu, 11 Aug 2022 15:37:41 +0200 (CEST)
Received: from *****.aznetwork.eu ([127.0.0.1])
by localhost (*****.aznetwork.eu [127.0.0.1]) (amavisd-new, port 10032)
with ESMTP id Tin75ip0CVd1 for <recipient#mail.com>;
Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Received: from localhost (localhost.localdomain [127.0.0.1])
by *****.aznetwork.eu (Postfix) with ESMTP id B55251C6446
for <recipient#mail.com>; Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
X-Virus-Scanned: amavisd-new at *****.aznetwork.eu
Received: from *****.aznetwork.eu ([127.0.0.1])
by localhost (*****.aznetwork.eu [127.0.0.1]) (amavisd-new, port 10026)
with ESMTP id 4lpOVXL1yFKw for <recipient#mail.com>;
Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Received: from *****.aznetwork.eu (*****.aznetwork.priv [*****])
by *****.aznetwork.eu (Postfix) with ESMTP id 9E4CB1C631E
for <recipient#mail.com>; Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Date: Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
From: Sender Name <sender#mail.com>
To: recipient#mail.com
Message-ID: <1682353652.2846324.1660225060639.JavaMail.zimbra#aznetwork.eu>
Subject: [EXTERNE] Read-Receipt: Mail Subject
Auto-Submitted: auto-replied (zimbra; read-receipt)
Precedence: bulk
Return-Path: <>
X-MS-Exchange-Organization-ExpirationStartTime: 11 Aug 2022 13:37:41.4732
(UTC)
X-MS-Exchange-Organization-ExpirationStartTimeReason: OriginalSubmit
X-MS-Exchange-Organization-ExpirationInterval: 1:00:00:00.0000000
X-MS-Exchange-Organization-ExpirationIntervalReason: OriginalSubmit
X-MS-Exchange-Organization-Network-Message-Id:
384141c3-c532-4391-771a-08da7b9eaa12
X-EOPAttributedMessage: 0
X-EOPTenantAttributedMessage: 873b62a6-6fcf-467d-8380-ce41a1d6da9f:0
X-MS-Exchange-Organization-MessageDirectionality: Incoming
X-MS-PublicTrafficType: Email
X-MS-Exchange-Organization-AuthSource:
*****.prod.protection.outlook.com
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Office365-Filtering-Correlation-Id: 384141c3-c532-4391-771a-08da7b9eaa12
X-MS-TrafficTypeDiagnostic: AM9PR02MB7641:EE_
Content-Type: multipart/mixed;
boundary="_16f20566-32fe-437d-8fb6-e2fcbadabd01_"
X-MS-Exchange-Organization-SCL: 1
X-Microsoft-Antispam: BCL:0;
X-Forefront-Antispam-Report:
CIP:*****;CTRY:FR;LANG:fr;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:*****.aznetwork.eu;PTR:*****.aznetwork.eu;CAT:NONE;SFS:(13230016)(36756003)(7696005)(6266002)(26005)(564344004)(356005)(7636003)(336012)(426003)(2616005)(66574015)(42882007)(83380400001)(78352004)(5660300002)(8676002)(6916009)(1096003);DIR:INB;
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2022 13:37:41.3795
(UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 384141c3-c532-4391-771a-08da7b9eaa12
X-MS-Exchange-CrossTenant-Id: 873b62a6-6fcf-467d-8380-ce41a1d6da9f
X-MS-Exchange-CrossTenant-AuthSource:
*****.prod.protection.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: Internet
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR02MB7641
X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.2537846
X-MS-Exchange-Processed-By-BccFoldering: 15.20.5525.010
X-Microsoft-Antispam-Mailbox-Delivery:
ucf:0;jmr:0;auth:0;dest:I;ENG:(910001)(944506458)(944626604)(920097)(930097);
X-Microsoft-Antispam-Message-Info:
=?iso-8859-1?somebase64data=
MIME-Version: 1.0
--_16f20566-32fe-437d-8fb6-e2fcbadabd01_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
ATTENTION: Ce message est originaire de l'ext=E9rieur de ***. Ne pas clique=
r sur les liens internet ou ouvrir les pi=E8ces jointes =E0 moins que vous =
ne connaissiez l'auteur ou sachiez que le contenu est sain (pas de virus).
--_16f20566-32fe-437d-8fb6-e2fcbadabd01_
Content-Type: message/rfc822
X-MS-Exchange-Organization-InternalOrgSender: True
Received: from *****.PROD.OUTLOOK.COM (*****) by
*****.prod.outlook.com (*****) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.23; Thu, 11 Aug
2022 13:37:41 +0000
Received: from *****.prod.protection.outlook.com
(*****) by *****.outlook.office365.com
(*****) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11 via Frontend
Transport; Thu, 11 Aug 2022 13:37:41 +0000
Authentication-Results: spf=none (sender IP is *****)
smtp.helo=*****.aznetwork.eu; dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=aznetwork.eu;
Received-SPF: None (protection.outlook.com: *****.aznetwork.eu does not
designate permitted sender hosts)
Received: from *****.aznetwork.eu (*****) by
*****.mail.protection.outlook.com (*****) with Microsoft SMTP
Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
15.20.5525.11 via Frontend Transport; Thu, 11 Aug 2022 13:37:41 +0000
Received: from localhost (localhost.localdomain [127.0.0.1])
by *****.aznetwork.eu (Postfix) with ESMTP id 053BC1C631E
for <recipient#mail.com>; Thu, 11 Aug 2022 15:37:41 +0200 (CEST)
Received: from *****.aznetwork.eu ([127.0.0.1])
by localhost (*****.aznetwork.eu [127.0.0.1]) (amavisd-new, port 10032)
with ESMTP id Tin75ip0CVd1 for <recipient#mail.com>;
Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Received: from localhost (localhost.localdomain [127.0.0.1])
by *****.aznetwork.eu (Postfix) with ESMTP id B55251C6446
for <recipient#mail.com>; Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
X-Virus-Scanned: amavisd-new at *****.aznetwork.eu
Received: from *****.aznetwork.eu ([127.0.0.1])
by localhost (*****.aznetwork.eu [127.0.0.1]) (amavisd-new, port 10026)
with ESMTP id 4lpOVXL1yFKw for <recipient#mail.com>;
Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Received: from *****.aznetwork.eu (*****.aznetwork.priv [*****])
by *****.aznetwork.eu (Postfix) with ESMTP id 9E4CB1C631E
for <recipient#mail.com>; Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Date: Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
From: Sylvain DEVIDAL <sender#mail.com>
To: recipient#mail.com
Message-ID: <1682353652.2846324.1660225060639.JavaMail.zimbra#aznetwork.eu>
Subject: [EXTERNE] Read-Receipt: Mail Subject
Content-Type: multipart/report;
boundary="----=_Part_2846322_558173291.1660225060636"; report-type=disposition-notification
Auto-Submitted: auto-replied (zimbra; read-receipt)
Precedence: bulk
Return-Path: <>
X-MS-Exchange-Organization-OriginalArrivalTime: 11 Aug 2022 13:37:41.3795
(UTC)
X-MS-Exchange-Organization-ExpirationStartTime: 11 Aug 2022 13:37:41.4732
(UTC)
X-MS-Exchange-Organization-ExpirationStartTimeReason: OriginalSubmit
X-MS-Exchange-Organization-ExpirationInterval: 1:00:00:00.0000000
X-MS-Exchange-Organization-ExpirationIntervalReason: OriginalSubmit
X-MS-Exchange-Organization-Network-Message-Id:
384141c3-c532-4391-771a-08da7b9eaa12
X-MS-Exchange-Organization-OriginalClientIPAddress: *****
X-MS-Exchange-Organization-OriginalServerIPAddress: *****
X-EOPAttributedMessage: 0
X-EOPTenantAttributedMessage: 873b62a6-6fcf-467d-8380-ce41a1d6da9f:0
X-MS-Exchange-Organization-TargetResourceForest: *****.prod.outlook.com
X-MS-Exchange-Organization-OrgEopForest: EUR01
X-MS-Exchange-Organization-MessageDirectionality: Incoming
X-MS-Exchange-Organization-Id: 873b62a6-6fcf-467d-8380-ce41a1d6da9f
X-MS-Exchange-Organization-FFO-ServiceTag: EUR01B
X-MS-Exchange-Organization-Cross-Premises-Headers-Processed:
*****.prod.protection.outlook.com
X-MS-Exchange-Organization-ConnectingIP: *****
X-MS-Exchange-Organization-ConnectingEHLO: *****.aznetwork.eu
X-MS-Exchange-Organization-AS-LastExternalIp: *****
X-MS-Exchange-Organization-Originating-Country: FR
X-MS-Exchange-Organization-OriginalEnvelopeRecipients: recipient#mail.com
X-MS-Exchange-Organization-PtrDomains: *****.aznetwork.eu
X-MS-Exchange-Organization-EhloAndPtrDomain:
*****.aznetwork.eu;*****.aznetwork.eu
X-MS-Exchange-Organization-MxPointsToUs: true
X-MS-Exchange-Organization-RecipientMxInfo-PFAFD:
recipientdomain.com#*****.mail.protection.outlook.com
X-MS-Exchange-Organization-CompAuthRes: pass
X-MS-Exchange-Organization-CompAuthReason: 105
X-MS-Exchange-Organization-SpoofDetection-Frontdoor-DisplayDomainName:
aznetwork.eu
X-MS-Exchange-Organization-Auth-ExtendedDmarcStatus: Pass
X-MS-Exchange-Organization-SenderRep-Score: 3
X-MS-Exchange-Organization-SenderRep-Data:
IpClassSmallGrayBest_SmallGrayBest_unknown
X-MS-Exchange-Organization-VBR-Class: SmallGrayBest
X-MS-Exchange-Organization-HMATPModel-Spf: 5
X-MS-Exchange-Organization-HMATPModel-Recipient:
*****
X-MS-Exchange-Organization-TransportTrafficType: Email
X-MS-PublicTrafficType: Email
X-MS-Exchange-Organization-OrderedPrecisionLatencyInProgress:
LSRV=*****.PROD.OUTLOOK.COM:TOTAL-FE=0.093|SMR-PEN=0.082(RENV=0.068);2022-08-11T13:37:41.721Z
X-MS-Exchange-Organization-MessageLatency:
SRV=*****.eop-EUR01.prod.protection.outlook.com:TOTAL-FE=0.247|SMR-PEN=0.221(RENV=0.031(SMRRC=0.029(SMRRC-TenantAttributionAndInboundConnectorAgent=0.026
))|REOH=0.189(SMREH=0.127(SMREH-Protocol Filter Agent=0.124)))|SMS=0.029
X-MS-Exchange-Organization-MessageLatency:
SRV=*****.PROD.OUTLOOK.COM:TOTAL-FE=0.116|SMR-PEN=0.082(RENV=0.068)|SMS=0.023(SMSC=0.033)
X-MS-Exchange-Forest-ArrivalHubServer: *****.prod.outlook.com
X-MS-Exchange-Organization-AuthSource:
*****.prod.protection.outlook.com
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-FromEntityHeader: Internet
X-MS-Exchange-Organization-MessageScope: 7ca5d36b-aa6e-4988-8ce2-ebc9e7a7fc2a
X-MS-Exchange-Forest-MessageScope: 7ca5d36b-aa6e-4988-8ce2-ebc9e7a7fc2a
X-MS-Exchange-Organization-Antispam-ProtocolFilterHub-ScanContext:
ProtocolFilterHub:SmtpOnEndOfData;
X-MS-Office365-Filtering-Correlation-Id: 384141c3-c532-4391-771a-08da7b9eaa12
X-MS-Exchange-Organization-P2SenderDisplayNamePII:
H101(Oo2uoTVO0nYrZjTS6UNDuqjuYq+ejtD0u3d/6RR1MgI=)
X-MS-Exchange-Organization-P2SenderPII:
*****
X-MS-Exchange-Organization-PFAHub-Total-Message-Size: 9121
X-MS-Exchange-Organization-OriginalSize: 9121
X-MS-TrafficTypeDiagnostic: AM9PR02MB7641:EE_
X-MS-Exchange-Organization-HygienePolicy: Premium
X-MS-Exchange-Organization-ReplicationInfo:
ReplicaId=9de80d70-aee0-b1f9-8fed-3baa9e7bda08;ReplicatingServerFqdn=*****.eurprd02.prod.outlook.com
X-MS-Exchange-Forest-Language: fr
X-MS-Exchange-Forest-IndexAgent-0:
Somebase64data=
X-MS-Exchange-Forest-IndexAgent: 1 833
X-MS-Exchange-Forest-EmailMessageHash: 6E6C2B22,31F80CB7
X-MS-Exchange-Organization-PhishSim-Rules-Execution-History:
336d57ef-0937-4345-9ee7-7488d99e1eee
X-MS-Exchange-Organization-Antispam-PreContentFilter-PolicyLoadTime:
PSOSUB:6;PSOSUBLOAD:5;PSOSUBRUN:0;PSOSUBCOUNT:1;SMORES:2;SMORESLOAD:1;SMORESRUN:0;SMORESCOUNT:0;SAORES:4;SAORESLOAD:1;SLORES:2;APORES:22;APORESLOAD:1;APORESRUN:20;APORESCOUNT:2;RSORES:1;SLORESLOAD:1;
X-MS-Exchange-Organization-AttachmentDetailsHeaderStamp-Success: 1.0
X-MS-Exchange-Organization-AttachmentDetails:
0:EpUTydEBwSuS9oq8FNAFHYcMPGvyaOa9tpBsGPTlB4k=:U:Text:QVRUMDAwMDQ=::#:False:::N:::N::N:None:
X-MS-Exchange-Organization-MessageFingerprint:
A0DBCBFD.2F1B0759.C2DDF092.B4130E24.200A4
X-MS-Exchange-Organization-AttachmentDetailsInfo-ChunkCount: 1
X-MS-Exchange-Organization-AttachmentDetailsInfo-0:
[{"ID":0,"FS":308,"HFH":"EpUTydEBwSuS9oq8FNAFHYcMPGvyaOa9tpBsGPTlB4k=","FE":"","CEXT":[],"CFT":[],"AF":0,"AFT":"{784:\"ATT00004\",789:\"text\"}"}]
X-MS-Exchange-Organization-FeatureTable:
{385:"aznetwork.eu",452:1,453:1,454:"4A71A110#kp1.fr",504:7,506:4,507:5,508:"none",509:"aznetwork.eu",510:"*****.aznetwork.eu",651:2,653:1,656:1,721:"2.37",722:"2.35",742:1,743:3,744:1,748:"sign",749:"Latn",758:"A0DBC8FE.2F5B0759.F0DDB08F.A01F8E26.20082",781:1,782:8,1010:0,1011:"1830FF39|60572074|",1101:"0.194"}
X-MS-Exchange-Organization-MetadataFeatureTable:
{756:0,757:0,1010:0,1011:"1830FF39|60572074|",1036:"199167"}
X-MS-Exchange-Organization-Antispam-PreContentFilter-ScanContext:
CategorizerOnSubmitted;CategorizerOnResolved;
X-MS-Exchange-Organization-AVScannedByV2: true
X-MS-Exchange-Organization-AVScanComplete: true
X-MS-Exchange-Organization-ExternalRoutingTopologyAnalysis:
X-MS-Exchange-Organization-Recipient-Limit-Verified: True
X-MS-Exchange-Organization-TotalRecipientCount: 1
X-MS-Exchange-Organization-HVERecipientsForked: 1.0
X-MS-Exchange-Organization-AntiPhishPolicy: Default_kp1
X-MS-Exchange-Organization-ASDirectionalityType: 1
X-MS-Exchange-Organization-Boomerang-Verdict: None
X-MS-Exchange-Organization-HMATPModel-DkimAuthStatus: 7
X-MS-Exchange-Organization-HMATPModel-DmarcAuthStatus: 4
X-MS-Exchange-Organization-Cross-Session-Cache:
=?utf-8?somebase64data=
X-MS-Exchange-Organization-Cross-Session-Cache:
01xSupported=1;TMD_SS=1;TMD_AOT=3433;TMD_CSUM=5377;TMD_DTAET=1;TMD_ES=0;TMD_TT=0;TMD_DMNSPM=8914;TMD_DMSPM=338;TMD_PSATP=0;TMD_PS=1939;TMD_SCNT=5;TMD_TSATP=0;TMD_TS=0;TMD_ATPP2=False;TMD_CI=fr-FR;TMD_CD=2013-03-15
09:53:51.000;TMD_NEWT=0;TMD_NEWTT=0;TMD_QS=1;TR_SS=1;TR_SMAS=0;TR_TMAS=0;TR_UMAS=0;TR_TTU24H=0;TR_TT24H=0;TR_AFWR24H=18;TR_NDRSPMR24H=0;TR_R1H=315;TR_R24H=2709;TR_SPMR1H=0;TR_SPMR24H=0;TR_UP1R1H=0;TR_UP1R24H=0;TR_UP1SPMR24H=0;TR_QS=1;BR_V=None;DIR=1;PTRO=aznetwork.eu;P2O=aznetwork.eu;P_CAUTH=pass;P_CAUTHR=105;SIP2BCLAP=-1;SIP2BCLAF=-1;P2BCL=
X-MS-Exchange-Organization-Rules-Execution-History:
95544e5a-848e-428b-b1a3-43568aa659bf%%%5a9c7fc7-bc74-434e-81a5-8fe8f957dcbb%%%22b9f62e-47d3-4bb9-87f7-b1c42aa1f5e3%%%79dacf70-5b24-4672-8325-97733f56b4e3%%%572c1ac3-7cd0-4e7c-8a3b-99003d82e392
MIME-Version: 1.0
------=_Part_2846322_558173291.1660225060636
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Le mail envoy=C3=A9 le 11 ao=C3=BBt 2022 =C3=A0 15:37:26 GMT+02:00 au desti=
nataire sender#mail.com avec l=E2=80=99objet "Mail=
subject" a =C3=A9t=C3=A9 affich=C3=A9. Cela ne signifie aucunement =
que ce mail ait =C3=A9t=C3=A9 lu (ou compris).=
------=_Part_2846322_558173291.1660225060636
Content-Type: message/disposition-notification; charset=utf-8
Content-Transfer-Encoding: 7bit
Reporting-UA: 78.252.48.37; ZimbraWebClient - GC104 (Win)/8.8.15_GA_4257
Original-Recipient: rfc822;sender#mail.com
Final-Recipient: rfc822;sender#mail.com
Original-Message-ID: <YA0XNMBBLHU4.N87S2N70CKU81#dev-crm22-upd1>
Disposition: manual-action/MDN-sent-manually; displayed
------=_Part_2846322_558173291.1660225060636--
--_16f20566-32fe-437d-8fb6-e2fcbadabd01_--
(sorry for the long code)
You can see at line 147 it actually contains the original message, of type "report" (it was a read reciept).
But whatever I try, I can't parse it.
Here is my current code: (message id the mail message as I load if from mailbox)
public static void ProcessReadReceiptNotification(MimeMessage message)
{
/// This part is the "standard way" to find a read-reciept, but it doesn't work
var report = message.Body as MultipartReport;
if (report == null || report.ReportType == null || !report.ReportType.Equals("disposition-notification", StringComparison.OrdinalIgnoreCase))
{
// this is not a read receipt notification message...
Console.WriteLine("this is not a read receipt notification message... will parse parts");
/// Then I tried to iterate all parts of the mail then load the message
foreach (MimeEntity part in message.BodyParts)
{
Console.WriteLine($"A part of type {part.ContentType.MimeType} is found");
if (part.ContentType.MimeType == "message/rfc822")
{
/// Here part.Message private property contains the message
Console.WriteLine("This is a message, we load it");
using MemoryStream ms = new();
part.WriteTo(ms);
ms.Seek(0, SeekOrigin.Begin);
MimeMessage msg = MimeMessage.Load(ms);
/// Here my msg object is empty, or at least doesn't contain message data (subject, body, etc.)
//Console.WriteLine(msg.Body.ToString());
report = msg.Body as MultipartReport;
Console.WriteLine(report?.ToString());
/*
return ProcessReadReceiptNotification(msg);
*/
}
}
Console.Write("Nothing found...");
return;
}
else
{
Console.WriteLine($"Report Type : {report.ReportType}");
// process the report
foreach (var mds in report.OfType<MessageDispositionNotification>())
{
Console.WriteLine($"{mds.Content}");
var messageId = mds.Fields.Single(a => a.Field == "Original-Message-ID");
if (messageId is not null)
{
Console.Write($"Le message {messageId.Value}");
}
var readStatus = mds.Fields.Single(a => a.Field == "Disposition");
if (readStatus is not null)
{
var index = readStatus.Value.IndexOf(";");
Console.WriteLine($" a été {readStatus.Value.Substring(index + 1)}.");
}
return;
}
return;
}
}
How could I load this body part and identify it's a read-reciept (with it's original message id)?
I found that in the part.Message private property I can see the original message. But I can't access to it. part.WriteTo(ms) doesn't copy the message.

I finaly found how to read the original message.
Rather than loading the part as a MimeMessage I just had to load it as a MultipartReport...
foreach (MimeEntity part in message.BodyParts)
{
Console.WriteLine($"A part of type {part.ContentType.MimeType} is found");
if (part.ContentType.MimeType == "message/rfc822")
{
Console.WriteLine("This is a message, we load it");
using MemoryStream ms = new();
part.WriteTo(ms, true);
ms.Seek(0, SeekOrigin.Begin);
report = MimeEntity.Load(ms) as MultipartReport;
Console.WriteLine(report?.ToString());
}
}

There's no need to write the content out to a stream only to re-parse it again.
All you need to do is this:
foreach (MimeEntity part in message.BodyParts)
{
Console.WriteLine($"A part of type {part.ContentType.MimeType} is found");
// MessageParts are message/rfc822 (or equivalent such as message/news
// or message/global which is the UTF-8 version of message/rfc822)
//
// Never use case-sensitive string comparisons like
// part.ContentType.MimeType == "message/rfc822" because MIME does not
// restrict things to lowercase. Instead, the recommended way of checking
// for an exact mime-type is part.ContentType.IsMimeType("message", "rfc822")
// or
// part.ContentType.MimeType.Equals("message/rfc822", StringComparison.OrdinalIgnoreCase).
if (part is MessagePart rfc822)
{
Console.WriteLine("This is a message, lets see if the body is a multipart/report");
if (rfc822.Body is MultipartReport report)
{
// handle the multipart/report which is already in a parsed state
}
}
}

Related

Office.context.mailbox.item.internetHeaders.setAsync is not set

I am using the office api within outlook. I'm trying to set an additional x-header to my mail in the composer scope, so I can identify the mail later on.
I used this documentation here to create my bits of code:
https://learn.microsoft.com/en-us/javascript/api/outlook/office.internetheaders?view=outlook-js-preview
Office.context.mailbox.item.internetHeaders.setAsync({"x-sap-mail-addin-id": this.state.addinMailId}, {
}, (assyRes) => {
Office.context.mailbox.item.internetHeaders.getAsync(["x-sap-mail-addin-id"], { }, (val) => {
console.log(val);
});
console.log(assyRes);
});
As the screens show, the value is set right now.
So I tried to read the mail from the MS Graph (and got it) as follows:
var configuration = provider.GetService<ConfigurationService>();
var clientApp = ConfidentialClientApplicationBuilder
.Create(configuration.AzureAD.ApplicationId)
.WithTenantId(configuration.AzureAD.TenantId)
.WithClientSecret(configuration.AzureAD.AppSecret)
.Build();
var authProvider = new ClientCredentialProvider(clientApp);
var graphClient = new GraphServiceClient(authProvider);
var messageStream = await graphClient.Users["mail2sap-sendmail#gisdev.onmicrosoft.com"].Messages["AAMkADMzNDg3YTFiLWI4NDItNDI5Ni1hNzU1LTE3YmRhYjZkYzFjMwBGAAAAAABc2UL4pp4rRoxnwy3lWAHyBwAmKhkFHv2sRIc0wWWwSW0lAAAAAAEMAAAmKhkFHv2sRIc0wWWwSW0lAAAAAAlEAAA="].Content.Request().GetAsync();
var messageMetaData = await graphClient.Users["mail2sap-sendmail#gisdev.onmicrosoft.com"].Messages.Request().GetAsync();
So I'd have expected the header to be somewhere here:
But neither the Guid nor the attribute name can be found in the entire message text.
Same is true for the meta data from the graph.
What am I doing wrong here?
EDIT: Here is what I got from graph:
Received: from AM0PR09MB4036.eurprd09.prod.outlook.com (2603:10a6:208:19f::13)
by DB8PR09MB4058.eurprd09.prod.outlook.com with HTTPS; Thu, 6 May 2021
07:53:21 +0000
Received: from AM9PR09MB4593.eurprd09.prod.outlook.com (2603:10a6:20b:287::6)
by AM0PR09MB4036.eurprd09.prod.outlook.com (2603:10a6:208:19f::13) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.27; Thu, 6 May
2021 07:53:21 +0000
Received: from AM9PR09MB4593.eurprd09.prod.outlook.com
([fe80::c008:da09:d9b2:47cc]) by AM9PR09MB4593.eurprd09.prod.outlook.com
([fe80::c008:da09:d9b2:47cc%4]) with mapi id 15.20.4108.026; Thu, 6 May 2021
07:53:20 +0000
From: User <User#tenant.onmicrosoft.com>
To: User <User#tenant.onmicrosoft.com>
Subject: 123
Thread-Topic: 123
Thread-Index: AQHXQkdWc7SsFNH9wEqedVXYoSRrXQ==
Date: Thu, 6 May 2021 07:53:20 +0000
Message-ID:
<LONGID#AM9PR09MB4593.eurprd09.prod.outlook.com>
Accept-Language: en-DE, en-GB, en-US, de-DE
Content-Language: aa
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 04
X-MS-Exchange-Organization-AuthSource: AM9PR09MB4593.eurprd09.prod.outlook.com
X-MS-Has-Attach:
X-MS-Exchange-Organization-Network-Message-Id:
MESSAGE_ID
X-MS-Exchange-Organization-SCL: -1
X-MS-TNEF-Correlator:
X-MS-Exchange-Organization-RecordReviewCfmType: 0
x-ms-publictraffictype: Email
X-Microsoft-Antispam-Mailbox-Delivery:
ucf:0;jmr:0;auth:0;dest:I;ENG:(750129)(520011016)(706158)(944506458)(944626604);
X-Microsoft-Antispam-Message-Info:
didRz2nSjLEkd9U7ivulQq20MhG39bFkrSpiT//1gM51su3XDIz+haWsUqAYbfT7XVFmv7/sHNnDbS9pAvqN3lt8juTcmd4kiXLclZf6HsXGy9aBC5BbqSN5dgq5rTQ+1vjMZS6dlbbVvEb96d9B9BkOCTdYexnWDW6y4BQjwqAMthoSs3a9Dlr3TOy9ijC6DltkRQOt9lqQqtPViwoPqLnpF42EC5Lk98xKvWHHomRTcW3tcTL05mpAgvH5bLGZvjvBwllG9tpJvecs+PFXsZjfK3gTRMbEB4/yVw4QaqQcCL2zQsRYgJKNt7r3Vp3Jol6xhR/45FAntpFrJKio2Qwzmh4iQdAXvxZj/tR0e9c=
Content-Type: multipart/alternative;
boundary="_000_AM9PR09MB45936DB89D92E97CAF50EBF2FB589AM9PR09MB4593eurp_"
MIME-Version: 1.0
--_000_AM9PR09MB45936DB89D92E97CAF50EBF2FB589AM9PR09MB4593eurp_
Content-Type: text/plain; charset="us-ascii"
sd
--_000_AM9PR09MB45936DB89D92E97CAF50EBF2FB589AM9PR09MB4593eurp_
Content-Type: text/html; charset="us-ascii"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
sd</div>
</body>
</html>
--_000_AM9PR09MB45936DB89D92E97CAF50EBF2FB589AM9PR09MB4593eurp_--
You will need to call item.getAllInternetHeadersAsync to get internet headers on the current message in Read mode. This API will get all of the internet headers on the item, and you can filter the asyncResult.value for the header you are interested in.

Exchange Meeting Forward Notification: How to retrieve original meeting?

I've been hunting for this information for a week without any solid success.
I am targeting an Exchange 2010_SP2 server and have an application which sends out Appointments (Meetings) using EWS and inviting users/attendees. Currently when a user forwards their calendar item to another user, Exchange sends my application's email address an automatic notification about the forward. From the information contained within the notification message, I cannot find any information to help me specifically bind to the original appointment. I do have some clues with the user that forwarded it, the title of the event, and the date/time for it, but nothing that is guaranteed to be unique. I was thinking I could embed a unique identifier into the subject, but this seems a little gross. Has anyone else figured out a way to look up the event in context?
(Using C# and Microsoft's EWS Client API)
case EmailMessage fw when fw.ItemClass == "IPM.Schedule.Meeting.Notification.Forward":
EmailMessage message = EmailMessage.Bind(Global.Exchange, fw.Id);
message.Load();
I have attempted to try to query for the conversation, tried attaching customer X-Parameters to the original meeting, and have inspected all the properties I can think of within an EmailMessage object.
Example of a forward notification:
Internet Headers attached to the Email: (some parts redacted using ----)
Received: from FMSEDG002.ED.cps.----.com (10.1.192.134) by
fmsmsx121.amr.corp.----.com (10.18.125.36) with Microsoft SMTP Server (TLS)
id 14.3.439.0; Sat, 13 Jun 2020 14:24:33 -0700
Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.36.54) by
edgegateway.----.com (192.55.55.69) with Microsoft SMTP Server (TLS) id
14.3.439.0; Sat, 13 Jun 2020 14:24:33 -0700
Received: from BYAPR11MB3830.namprd11.prod.outlook.com (2603:10b6:a03:fc::14)
by BYAPR11MB3797.namprd11.prod.outlook.com (2603:10b6:a03:fe::27) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.22; Sat, 13 Jun
2020 21:24:30 +0000
Received: from BYAPR11MB3830.namprd11.prod.outlook.com
([fe80::9d21:2f25:9b76:e341]) by BYAPR11MB3830.namprd11.prod.outlook.com
([fe80::9d21:2f25:9b76:e341%7]) with mapi id 15.20.3088.027; Sat, 13 Jun 2020
21:24:30 +0000
Content-Type: multipart/mixed;
boundary="_000_BYAPR11MB383088E85E5BF51D212384F4F99E0BYAPR11MB3830namp_"
From: ----
To: ----
Subject: Meeting Forward Notification: Dummy Event - Example 3
Thread-Topic: Meeting Forward Notification: Dummy Event - Example
3
Sender: Microsoft Outlook
<MicrosoftExchange32----#----.onmicrosoft.com>
Date: Sat, 13 Jun 2020 21:24:30 +0000
Message-ID: <BYAPR11MB383088E85E5BF51D212384F4F99E0#BYAPR11MB3830.namprd11.prod.outlook.com>
X-MS-Has-Attach:
X-MS-TNEF-Correlator: <BYAPR11MB383088E85E5BF51D212384F4F99E0#BYAPR11MB3830.namprd11.prod.outlook.com>
authentication-results: ----; dkim=none (message not signed)
header.d=none;----; dmarc=none action=none header.from=----;
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: 53ede74f-9111-4b3f-01ff-08d80fe028c7
x-ms-traffictypediagnostic: BYAPR11MB3797:
x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr
x-ms-oob-tlc-oobclassifiers: OLM:2089;
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: bevNkvUhwfDB1JTruSgvhewEnlseaRPl5vEl4tx04MJVY/bY7tbeShWgjWHsg2ZEGmWH2ZZN2rjA4NjqI9seC5ei1B9A0m8tvCr7Ij+3IJAUr8vYz0F7LRwVKE2nZB1E7Wy7V3pHvYxyT6tyOvjbxDeHN7Fbs0dvKYwj4g/EWxAEiXNmGFxkPXGowV3I1v2vWT+hBIIO6Sz1Lg8/jzPm7l6d9DZZ7gxjQDQfuAcBgQEUj46RqNlMosWGEK65oBHWTYRC4R2oc3z2qS3Y8VgIzg==
x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:-1;SRV:;IPV:NLI;SFV:SKI;H:BYAPR11MB3830.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:INB;SFP:;
x-ms-exchange-transport-forked: True
MIME-Version: 1.0
X-MS-Exchange-CrossTenant-Network-Message-Id: 53ede74f-9111-4b3f-01ff-08d80fe028c7
X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2020 21:24:30.0788
(UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3797
X-OrganizationHeadersPreserved: BYAPR11MB3797.namprd11.prod.outlook.com
Return-Path: <>
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 04
X-MS-Exchange-Organization-AuthSource: BYAPR11MB3830.namprd11.prod.outlook.com
X-CrossPremisesHeadersPromoted: ----
X-CrossPremisesHeadersFiltered: ----
X-MS-Exchange-Organization-SCL: -1
X-OriginatorOrg: intel.onmicrosoft.com
X-MS-Exchange-Organization-AVStamp-Mailbox: NAI;60104903;0;novirus
The PidLidCleanGlobalObjectId http://msdn.microsoft.com/en-us/library/cc839502.aspx extended should be set on the notification. You can use that to search for the Appointment eg this is on example of using that property
Appointment newAppointment = new Appointment(service);
newAppointment.Subject = "Test Subject";
newAppointment.Start = new DateTime(2016, 08, 27, 17, 00, 0);
newAppointment.StartTimeZone = TimeZoneInfo.Local;
newAppointment.EndTimeZone = TimeZoneInfo.Local;
newAppointment.End = newAppointment.Start.AddMinutes(30);
newAppointment.Save();
newAppointment.Body = new MessageBody(Microsoft.Exchange.WebServices.Data.BodyType.Text, "test");
newAppointment.RequiredAttendees.Add("attendee#domain.com");
newAppointment.Update(ConflictResolutionMode.AlwaysOverwrite ,SendInvitationsOrCancellationsMode.SendOnlyToAll);
ExtendedPropertyDefinition CleanGlobalObjectId = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, 0x23, MapiPropertyType.Binary);
PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
psPropSet.Add(CleanGlobalObjectId);
newAppointment.Load(psPropSet);
object CalIdVal = null;
newAppointment.TryGetProperty(CleanGlobalObjectId, out CalIdVal);
Folder AtndCalendar = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar,"attendee#domain.com"));
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(CleanGlobalObjectId, Convert.ToBase64String((Byte[])CalIdVal));
ItemView ivItemView = new ItemView(1);
FindItemsResults<Item> fiResults = AtndCalendar.FindItems(sfSearchFilter, ivItemView);
if (fiResults.Items.Count > 0) {
//do whatever
}

sometimes - Socket Error 10054 from email server, SMTP Client

I have a weird issue but not sure what to make of it,
I have a .net console application that prepares some data and FTP's it over
after the operation is complete it's supposed to send out a confirmation email - only what happens is that sometimes email is recieved, sometimes not
the application runs under a schedulear from SQL Job Agent using sql server 2014
the app is on the same server as the database , owner is sa and job is run under SQL Server agent - SQLSERVERAGENT has all the rights on the folder
Mail server being used is MDaemon, checking on the server logs it reveals that:
Fri 2016-08-12 06:28:50.387: 01: ----------
Fri 2016-08-12 06:31:24.154: 05: Session 834167; child 0001
Fri 2016-08-12 06:31:24.154: 05: Accepting SMTP connection from xxx to xxx
Fri 2016-08-12 06:31:24.164: 03: --> xxx ESMTP MDaemon 16.0.4; Fri, 12 Aug 2016 06:31:24 +1000
Fri 2016-08-12 06:31:24.164: 03: --> 220-Unauthorized relay prohibited.
Fri 2016-08-12 06:31:24.164: 03: --> 220 All transactions and IP are logged.
Fri 2016-08-12 06:31:24.167: 02: <-- EHLO OCSQL2
Fri 2016-08-12 06:31:24.168: 03: --> xxx Hello OCSQL2 [10.10.45.34], pleased to meet you
Fri 2016-08-12 06:31:24.168: 03: --> 250-ETRN
Fri 2016-08-12 06:31:24.168: 03: --> 250-AUTH LOGIN CRAM-MD5 PLAIN
Fri 2016-08-12 06:31:24.168: 03: --> 250-8BITMIME
Fri 2016-08-12 06:31:24.168: 03: --> 250-ENHANCEDSTATUSCODES
Fri 2016-08-12 06:31:24.168: 03: --> 250-STARTTLS
Fri 2016-08-12 06:31:24.168: 03: --> 250 SIZE
Fri 2016-08-12 06:31:24.168: 02: <-- MAIL FROM:<xxx>
Fri 2016-08-12 06:31:24.170: 01: xxx is an alias for xxx
Fri 2016-08-12 06:31:24.170: 03: --> 250 2.1.0 Sender OK
Fri 2016-08-12 06:31:24.170: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.175: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.175: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.265: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.266: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.270: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.270: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.275: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.276: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.281: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.281: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.286: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.286: 02: <-- DATA
Fri 2016-08-12 06:31:24.290: 01: Creating temp file (SMTP): e:\mdaemon\queues\temp\md50000008212.tmp
Fri 2016-08-12 06:31:24.290: 03: --> 354 Enter mail, end with <CRLF>.<CRLF>
Fri 2016-08-12 06:31:24.295: 01: Message size: 552 bytes
Fri 2016-08-12 06:31:24.323: 04: Socket error sending response to DATA
Fri 2016-08-12 06:31:24.324: 04: * Socket error 10054 - Connection was reset by the other side!
Fri 2016-08-12 06:31:24.324: 04: SMTP session terminated (Bytes in/out: 841/540)
code in the application:
public bool sendUploadNotification() {
var arrToEmail = toEmail.Split(';');
var arrCCEmail = ccEmail.Split(';');
MailMessage msg = new MailMessage();
string body;
string subject;
bool result = false;
if (logger.IsDebugEnabled) { logger.Debug("sending upload email"); }
try {
body = ReadBody();
subject = GetSubject();
if (logger.IsDebugEnabled) {
logger.Debug("ToEmail:" + toEmail + "," + "CCEmail:" + ccEmail + ",Subject:" + subject);
}
msg.IsBodyHtml = true;
msg.BodyEncoding = Encoding.UTF8;
msg.SubjectEncoding = Encoding.UTF8;
msg.From = new MailAddress(fromEmail,fromName);
msg.Subject = subject;
msg.Body = body;
foreach (var item in arrToEmail) {
msg.To.Add(new MailAddress(item));
}
foreach (var item in arrCCEmail) {
msg.CC.Add(new MailAddress(item));
}
client.Send(msg);
result = true;
if (logger.IsInfoEnabled) {
logger.Info("Upload confirmation email sent");
}
}
catch (Exception ex) {
if (logger.IsErrorEnabled) {
logger.Error("Error sending upload confirmation email", ex);
}
sendExceptionMail(ex);
result = false;
}
return result;
}
I'm not getting any exception in the application logs, everything is completed successfully.
the server has other .net modules which don't seem to have this problem, however other modules that send out emails are not triggered by SQL agent, they are called at runtime from the website
this problem seems to occur at random, most of the times it doesn't work, sometimes I have recieved the email as expected with no changes to the application or the server
I can't figure out why it's failing, searching google turned up some issue with windows 2008 server regarding tcp / ip stack but I'm on windows server 2012 R2 - the only thing that I can think if it may have to do with permissions, but it works sometimes
I have the same situation yesterday. For first, you will need to make sure of the email addresses are in correct format. believe me or not it can make you a problem.
Using System.ComponentModel;
foreach (var item in arrToEmail)
{
if (RegularExpressions.Regex.IsMatch(Strings.Trim(Sender), "^\\w+([-+.']\\w+)*#\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"))
{
msg.To.Add(new MailAddress(item));
}
}
foreach (var item in arrCCEmail)
{
if (RegularExpressions.Regex.IsMatch(Strings.Trim(Sender), "^\\w+([-+.']\\w+)*#\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"))
{
msg.CC.Add(new MailAddress(item));
}
}
Second, add the sender to your mail construction. MDaemon is very tricky and touchy.
msg.Sender = New MailAddress(credentialUser)
Third, Don't close the application too fast or dispose the "client" variable you have (assuming is a SMTPClient object). If the connection was dispose too fast, MDaemon think the 3rd party cancel the operation regardless if the mail structure is on MDaemon Server.
Optional, you can use Async Send Mail in your application. This will give you the confirmation and the right time of an email was sended (or failed).
For Example:
Before client.send(msg); in your code you can add this:
// Set the method that is called back when the send operation ends.
smtp.SendCompleted += SendCompletedCallback;
string userState = "Email Token or any text here to identify your Operation";
//This line will replace "client.send(msg)" code
smtp.SendAsync(msg, userState);
Somewhere in your code add this delegate:
private void SendCompletedCallback(object sender, AsyncCompletedEventArgs e) {
// Get the unique identifier for this asynchronous operation.
string token = e.UserState.ToString();
if (e.Cancelled) {
Console.WriteLine("[{0}] Send canceled.", token);
}
if (e.Error != null) {
Console.WriteLine("[{0}] {1}", token, e.Error.ToString());
}
else {
Console.WriteLine("Message sent.");
}
}
Hope it helps!

Email ends up in spam but only when sending from live website. Localhost works

I'm using a thirdparty SMTP service - turboSMTP
And I use it when sending emails from both localhost(when testing) and from the live website and both of them work. But the email sent from the live website always get flagged as spam, while the email from localhost is not flagged as spam.
Even if the sender email is the same. The content is the same. the title is the same and so on.
Does it actually see that I'm sending from a live website or from localhost when I'm sending through a third party SMTP service that isn't related to my webhost?
a cut from my code :
SmtpClient smtpClient = new SmtpClient();
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
mailMessage.From = new MailAddress(sender);
mailMessage.To.Add(recipient);
mailMessage.Subject = title;
mailMessage.Body = message;
mailMessage.IsBodyHtml = false;
smtpClient.Host = "smtpAddress";
smtpClient.UseDefaultCredentials = false;
smtpClient.EnableSsl = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Port = 587;
smtpClient.Credentials = new NetworkCredential("username", "password");
smtpClient.Send(mailMessage);
Email that got flagged as spam(Sent from live website)
Delivered-To: censoredAddress#gmail.com
Received: by 10.107.132.3 with SMTP id g3csp14274iod;
Thu, 4 Dec 2014 00:02:36 -0800 (PST)
X-Received: by 10.202.225.197 with SMTP id y188mr5614041oig.94.1417680156083;
Thu, 04 Dec 2014 00:02:36 -0800 (PST)
Return-Path: <noreply#censoredDomain.se>
Received: from tbjjbihbhcbji.turbo-smtp.net (tbjjbihbhcbji.turbo-smtp.net. [199.187.172.198])
by mx.google.com with SMTP id x10si17295964oek.84.2014.12.04.00.02.35
for <censoredAddress#gmail.com>;
Thu, 04 Dec 2014 00:02:36 -0800 (PST)
Received-SPF: fail (google.com: domain of noreply#censoredDomain.se does not designate 199.187.172.198 as permitted sender) client-ip=199.187.172.198;
Authentication-Results: mx.google.com;
spf=fail (google.com: domain of noreply#censoredDomain.se does not designate 199.187.172.198 as permitted sender) smtp.mail=noreply#censoredDomain.se;
dkim=temperror (no key for signature) header.i=#
Message-Id: <5480151c.8a283c0a.71e4.678eSMTPIN_ADDED_MISSING#mx.google.com>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=censoredDomain.se; s=turbo-smtp; x=1418284956; h=DomainKey-Signature:
Received:Received:MIME-Version:From:To:Date:Subject:Content-Type:
Content-Transfer-Encoding; bh=7vEAgi0RRzjrn+4Le/fcS1k1+tJ/Ro6XDU
4TKOlZ0JY=; b=Yu5q4UjDuGv2L/Fa3MR+FO4+h3jWj5KHKvDGZFCyJYj0+aB7aV
kgOix5W5zrlaJ0rbl39Ck08AORmO82jdcXzFdtFm5lst6ENG3JaWorxWyxduqWBI
TY7ZSzs9HJb4TBXcMQvvaPdM96VA7FP3i4vb4Q9mkoGX1nD6c9asLirsE=
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
s=turbo-smtp; d=censoredDomain.se;
h=Received:Received:X-TurboSMTP-Tracking:MIME-Version:From:To:Date:Subject:Content-Type:Content-Transfer-Encoding;
b=ttGj0ZR2T0aPVS+Q+0oEdy5VM4wWzIBm2DtLYvtUFyHhldqWO5n2kVnZN3m1pR
w0gGFX/r67i9FblNhg04ELxvsfO2+mHg0bhyTJgYOAPjS0DjoMBZI1WD2w/CTObN
VMxSkTu8Hq8CDe49SRsduLnVLUdg2zwt86eNxItLLTno0=;
Received: (qmail 1442 invoked from network); 4 Dec 2014 08:02:34 -0000
Received: from unknown (HELO Irwindale) (authenticated#212.247.113.26) by turbo-smtp.com with SMTP; 4 Dec 2014 08:02:34 -0000
X-TurboSMTP-Tracking: 1692405204
MIME-Version: 1.0
From: noreply#censoredDomain.se
To: censoredAddress#gmail.com
Date: 4 Dec 2014 09:02:34 +0100
Subject: Testar igen
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
asdasdasd
Email that did not get flagged as spam(Sent from localhost)
Delivered-To: censoredAddress#gmail.com
Received: by 10.107.132.3 with SMTP id g3csp14413iod;
Thu, 4 Dec 2014 00:03:46 -0800 (PST)
X-Received: by 10.60.150.194 with SMTP id uk2mr5861322oeb.37.1417680226570;
Thu, 04 Dec 2014 00:03:46 -0800 (PST)
Return-Path: <noreply#censoredDomain.se>
Received: from tbjjbihbhcbji.turbo-smtp.net (tbjjbihbhcbji.turbo-smtp.net. [199.187.172.198])
by mx.google.com with SMTP id a140si17357087oib.49.2014.12.04.00.03.45
for <censoredAddress#gmail.com>;
Thu, 04 Dec 2014 00:03:45 -0800 (PST)
Received-SPF: fail (google.com: domain of noreply#censoredDomain.se does not designate 199.187.172.198 as permitted sender) client-ip=199.187.172.198;
Authentication-Results: mx.google.com;
spf=fail (google.com: domain of noreply#censoredDomain.se does not designate 199.187.172.198 as permitted sender) smtp.mail=noreply#censoredDomain.se;
dkim=temperror (no key for signature) header.i=#
Message-Id: <54801561.924dca0a.a7bc.ffffe533SMTPIN_ADDED_MISSING#mx.google.com>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=censoredDomain.se; s=turbo-smtp; x=1418285025; h=DomainKey-Signature:
Received:Received:MIME-Version:From:To:Date:Subject:Content-Type:
Content-Transfer-Encoding; bh=7vEAgi0RRzjrn+4Le/fcS1k1+tJ/Ro6XDU
4TKOlZ0JY=; b=rW/7YJz7bCAsSz8EF2NTfU+JbIsh5A4QLAQ5EgrxJUG3j1vJmt
8aVAMEI+45iC79T/vFpfLrN1e+fuSXCXuiw9MhTgBvHG0w0JIiKpufyHUnIRmNUs
YjNRErfIhaHwtEgAFXL/0ou0sG7QrG2cKu8VP/P2WA7opvoC6tfgIQH6k=
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
s=turbo-smtp; d=censoredDomain.se;
h=Received:Received:X-TurboSMTP-Tracking:MIME-Version:From:To:Date:Subject:Content-Type:Content-Transfer-Encoding;
b=o5Vxv9MAQeyFm1EqkQ3f56XVgxzSOR2HNB7oqg6GqxP4qPy8QY9hBu2w5DPdf3
8d/HQqJX61zN4Rfnyxgrw2PMPXr5dsrpKnKyB3o1/FsGCLH3meLyO+LYxeQBLRFO
kKtUtQ4vvSy2TN+7Sefe18lQo+E6bUunTcg64kw2I//4E=;
Received: (qmail 11732 invoked from network); 4 Dec 2014 08:03:45 -0000
Received: from unknown (HELO Codecomp-HP) (authenticated#78.70.27.139) by turbo-smtp.com with SMTP; 4 Dec 2014 08:03:45 -0000
X-TurboSMTP-Tracking: 1692407529
MIME-Version: 1.0
From: noreply#censoredDomain.se
To: censoredAddress#gmail.com
Date: 4 Dec 2014 09:03:39 +0100
Subject: Testar igen
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
asdasdasd
You have an SPF fail in you mails:
spf=fail (google.com: domain of noreply#censoredDomain.se does not designate 199.187.172.198 as permitted sender)
Try adding the IP address (range) of the SMTP provider to your SPF record (or remove it completely).
You get that fail on both mails, so I do not know why one gets through, but the one failing is probalby caused by the SPF check.
Also the DKIM signature seems to be not correct:
dkim=temperror (no key for signature) header.i=#
You should check that with the SMTP provider.

Word 2010 reports an error after saving to WebDAV server

I've got a custom WebDAV server, built using Sphoirum webdav server, that resides inside an ASP.NET MVC3 application. It's a .Net 4.0 project.
The document repository is a SharePoint, where our MVC application is a front end to it, and exposes the whole thing via the WebDAV. Just to note we don't have WebDAV publishing enabled on our IIS 7.5.
I've implemented the following HTTP verbs:
Get
Head
Lock
Options
PropFind
Put
Unlock
Now, when I open a word document, it's first in the read only mode. Getting the lock and into edit mode is successful, but when I want to save the changes in my document I get the following:
Your changes were saved but could not be uploaded because of an error.
The trick is that document is indeed saved correctly to the repository, and the response from our WebDAV server to word is HTTP/200 but the Word complains nonetheless.
I've also tried editing in Word directly from the SharePoint repository, just to confirm that my Office isn't broken somehow - all works.
Here's the response from PUT request when saving the document from Word:
HTTP/1.1 200 OK
Date: Tue, 06 Sep 2011 12:25:47 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 12.0.0.6545
Last-Modified: Tue, 06 Sep 2011 12:25:47 GMT
ETag: "{F4A63494-D302-4C9B-9C57-D0CB0937A2B0},9"
ResourceTag: rt:F4A63494-D302-4C9B-9C57-D0CB0937A2B0#00000000009
X-MSDAVEXTLockTimeout: Second-3600
Lock-Token: opaquelocktoken:{F4A63494-D302-4C9B-9C57-D0CB0937A2B0}20110906T122532Z
Expires: Mon, 22 Aug 2011 12:25:47 GMT
Cache-Control: private,max-age=0
Content-Length: 0
Public-Extension: http://schemas.microsoft.com/repl-2
Set-Cookie: WSS_KeepSessionAuthenticated=40689; path=/
And here's the same response, for the same document, from our WebDAV server:
HTTP/1.1 200 OK
Cache-Control: private,max-age=0
Content-Length: 0
Expires: Wed, 24 Aug 2011 08:03:28 GMT
Last-Modified: Wed, 07 Sep 2011 08:03:28 GMT
ETag: "{4a4331a8-7df6-43e6-bd5f-bb80765e83a2},1"
Server: Microsoft-IIS/7.5
MS-Author-Via: DAV
ResourceTag: rt:4a4331a8-7df6-43e6-bd5f-bb80765e83a2#00000000001
Lock-Token: opaquelocktoken:{4a4331a8-7df6-43e6-bd5f-bb80765e83a2}20110907T080328Z
X-MSDAVEXTLockTimeout: Second-3600
Public-Extension: http://schemas.microsoft.com/repl-2
MicrosoftSharePointTeamServices: 12.0.0.6545
Set-Cookie: WSS_KeepSessionAuthenticated=40689; path=/
X-Powered-By: ASP.NET
Date: Wed, 07 Sep 2011 08:03:27 GMT
So I've tried to mimic some of the headers SharePoint emits, like MicrosoftSharePointTeamServices but to no avail.
By the way, I found the bug in Sphorium webdav that was causing this. The bug was in the method DavLockBase_InternalProcessDavRequest() and the incorrect line of code was:
string[] _lockTokens = this.RequestLock.GetLockTokens();
which should be:
string[] _lockTokens = this.ResponseLock.GetLockTokens();
After that change, saving files in Word 2010 worked fine.
If someone ever runs into this again, here is a fix that was built based on the above answer, and on what I have found from working with word 2010. Basically the fix involves replacing the code for the "DavLockBase_InternalProcessDavRequest" method (I've added some comments for each "correction").
As a note (found some info here): the behavior of the webdav implementation for word 2010 differs on whether there is a patch installed on the client side or not; therefore the 3rd correction may not be needed in all cases!
Hope it helps!
private int DavLockBase_InternalProcessDavRequest(object sender, EventArgs e)
{
int _responseCode = (int)DavLockResponseCode.Ok;
//string[] _lockTokens = this.RequestLock.GetLockTokens();
//#1 the above line is incorrect. replaced with the following:
string[] _lockTokens = this.ResponseLock.GetLockTokens();
//Check to see if a lock refresh was requested
if (base.HttpApplication.Request.Headers["If"] != null)
{
if (_lockTokens.Length == 1)
{
//#2 not sure why this should be done (or not), however I've seen this in other people corrections.
//DavRefreshEventArgs _refreshEventArgs = new DavRefreshEventArgs(_lockTokens[0], this.RequestLock.LockTimeout);
//OnRefreshLockDavRequest(_refreshEventArgs);
}
base.HttpApplication.Response.AppendHeader("Timeout", "Second-" + this.ResponseLock.LockTimeout);
}
else
{
//New lock request
StringBuilder _opaquelockTokens = new StringBuilder();
//#3 finally, added the check below, as most of the times, when using word 2010 there are no lock requests
if (_lockTokens.Length > 0)
{
foreach (string _lockToken in _lockTokens)
_opaquelockTokens.Append("<opaquelocktoken:" + _lockToken + ">");
base.HttpApplication.Response.AppendHeader("Lock-Token", _opaquelockTokens.ToString());
}
}
//Check to see if there were any process errors...
Enum[] _errorResources = this.ProcessErrorResources;
if (_errorResources.Length > 0)
{
//Append a response node
XmlDocument _xmlDocument = new XmlDocument();
XmlNode _responseNode = _xmlDocument.CreateNode(XmlNodeType.Element, _xmlDocument.GetPrefixOfNamespace("DAV:"), "response", "DAV:");
//Add the HREF
XmlElement _requestLockHrefElement = _xmlDocument.CreateElement("href", "DAV:");
_requestLockHrefElement.InnerText = base.RelativeRequestPath;
_responseNode.AppendChild(_requestLockHrefElement);
//Add the propstat
XmlElement _propstatElement = _xmlDocument.CreateElement("propstat", "DAV:");
XmlElement _propElement = _xmlDocument.CreateElement("prop", "DAV:");
XmlElement _lockDiscoveryElement = _xmlDocument.CreateElement("lockdiscovery", "DAV:");
_propElement.AppendChild(_lockDiscoveryElement);
_propstatElement.AppendChild(_propElement);
XmlElement _statusElement = _xmlDocument.CreateElement("status", "DAV:");
_statusElement.InnerText = InternalFunctions.GetEnumHttpResponse(DavLockResponseCode.FailedDependency);
_propstatElement.AppendChild(_statusElement);
_responseNode.AppendChild(_propstatElement);
base.SetResponseXml(InternalFunctions.ProcessErrorRequest(this.ProcessErrors, _responseNode));
_responseCode = (int)ServerResponseCode.MultiStatus;
}
else
{
//No issues
using (Stream _responseStream = new MemoryStream())
{
XmlTextWriter _xmlWriter = new XmlTextWriter(_responseStream, new UTF8Encoding(false));
_xmlWriter.Formatting = Formatting.Indented;
_xmlWriter.IndentChar = '\t';
_xmlWriter.Indentation = 1;
_xmlWriter.WriteStartDocument();
//Open the prop element section
_xmlWriter.WriteStartElement("D", "prop", "DAV:");
_xmlWriter.WriteStartElement("lockdiscovery", "DAV:");
this.ResponseLock.ActiveLock.WriteTo(_xmlWriter);
_xmlWriter.WriteEndElement();
_xmlWriter.WriteEndElement();
_xmlWriter.WriteEndDocument();
_xmlWriter.Flush();
base.SetResponseXml(_responseStream);
_xmlWriter.Close();
}
}
return _responseCode;
}
Observation: the lock token uses an invalid syntax (so does Sharepoints). Also; most of these headers shouldn't be needed (being proprietary) or do not apply to a PUT response (such as Lock-Token).
I would recommend to try publishing to Apache with mod_dav first, and to observe the HTTP exchange.

Categories

Resources