atm I'm implementing a custom solution in our SP 2010 farm to receive emails on an specific custom list.
With the following code it's possible to add one entry, with an email-body contains one line with values, seperated by ';' - i.e. (test;entry;in;our;sharepoint)
But now it's not cool, related to performance sending hundreds/thousands of mails in a minute to our sharepoint and insert every single item.
So I implemented in the same solution sth. to receive an email with multiple lines in a body (lines currently seperated by '~' and the single line still seperated by ';').
But there I can find the following error in the SharePoint log:
07/07/2015 12:02:56.85 OWSTIMER.EXE (0x13A4) 0x07F0 SharePoint Foundation E-Mail 6873 Warning An error occurred while processing the incoming e-mail file C:\inetpub\mailroot\Drop\15ed460901d0b89c00000008.eml. The error was: Object reference not set to an instance of an object.. ca05878c-e64b-4a32-bdf0-1916a8e8464a
And here's the code of my solution:
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
namespace incomail_proxylist.incomail
{
public class incomail : SPEmailEventReceiver
{
public override void EmailReceived(SPList list, SPEmailMessage emailMessage, String receiverData)
{
base.EmailReceived(list, emailMessage, receiverData);
string str = emailMessage.PlainTextBody;
string booli = emailMessage.Headers["subject"];
if (booli.Contains("COMPLETE_LIST"))
{
string[] entries = str.Split('~'); //new string[] { "\r\n", "\n" }, StringSplitOptions.None
for (int i = 0; i <= entries.Length; i++)
{
SPListItem newItem = list.Items.Add();
string[] arr = entries[i].Split(';');
newItem["Title"] = arr[0];
newItem["Host"] = arr[1];
newItem["Internal_IP"] = arr[2];
newItem["External_IP"] = arr[3];
newItem["Incoming_URL"] = arr[4];
newItem["Forwarding_URL"] = arr[5];
newItem["SSL"] = arr[6];
newItem["Status"] = arr[7];
newItem["ConfigPath"] = arr[8];
newItem.Update();
}
}
else
{
SPListItem newItem = list.Items.Add();
string[] arr = str.Split(';');
newItem["Title"] = emailMessage.Headers["subject"];
newItem["Host"] = arr[0];
newItem["Internal_IP"] = arr[1];
newItem["External_IP"] = arr[2];
newItem["Incoming_URL"] = arr[3];
newItem["Forwarding_URL"] = arr[4];
newItem["SSL"] = arr[5];
newItem["Status"] = arr[6];
newItem["ConfigPath"] = arr[7];
newItem.Update();
}
}
}
}
Edit: Adding an email like requested:
x-sender: server-a@domain.com
x-receiver: server-b@domain.com
Received: from exchange.domain.com ([ip of server]) by sharepoint.domain.com over TLS secured channel with Microsoft SMTPSVC(7.5.7600.16385);
Tue, 7 Jul 2015 10:53:37 +0200
Received: from exchange2.domain.com (ip of server) by
exchange.domain.com (ip of server) with Microsoft SMTP Server (TLS) id
14.3.224.2; Tue, 7 Jul 2015 10:53:32 +0200
Received: from server-a.domain.com (ip of server) by
exchange2.domain.com (ip of server) with Microsoft SMTP Server id
14.3.224.2; Tue, 7 Jul 2015 10:53:32 +0200
Message-ID: <686044.912410097-sendEmail@server-a>
From: Server-A <server-a@domain.com>
To: "server-b@domain.com" <server-b@domain.com>
Subject: COMPLETE_LIST
Date: Tue, 7 Jul 2015 08:53:32 +0000
X-Mailer: sendEmail-1.56
MIME-Version: 1.0
Content-Type: multipart/related;
boundary="----MIME delimiter for sendEmail-943467.83247693"
Return-Path: server-a@domain.com
X-OriginalArrivalTime: 07 Jul 2015 08:53:37.0598 (UTC) FILETIME=[69F27DE0:01D0B892]
------MIME delimiter for sendEmail-943467.83247693
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
title;server-a.domain.com;ip1;ip2;incomingURL;forwardingURL;active;/path/to/config-file~
title;server-a.domain.com;ip1;ip2;incomingURL;forwardingURL;active;/path/to/config-file~
title;server-a.domain.com;ip1;ip2;incomingURL;forwardingURL;active;/path/to/config-file~
title;server-a.domain.com;ip1;ip2;incomingURL;forwardingURL;active;/path/to/config-file~
title;server-a.domain.com;ip1;ip2;incomingURL;forwardingURL;active;/path/to/config-file~
title;server-a.domain.com;ip1;ip2;incomingURL;forwardingURL;active;/path/to/config-file~
title;server-a.domain.com;ip1;ip2;incomingURL;forwardingURL;active;/path/to/config-file~
title;server-a.domain.com;ip1;ip2;incomingURL;forwardingURL;active;/path/to/config-file~
------MIME delimiter for sendEmail-943467.83247693--
This is an example for an email like our exchange receives it.
I hided our internal information like IPs and hostnames.
But the structure is exactly the same!
Thanks in advance.