Friday, May 21, 2010

Receiving email to sharepoint list

Receiving an email to share point list is quite hard as compare to sending mail from list. This is one of the complicated thing on which I have worked in last few days. So here I am giving small solution for the problems that people are facing for this task, which I have seen on net while doing some goggling during task.The problems are like this type that list is enabled for receiving the mail but columns name not get updated ,how to debug the library..etc. Here i am giving some stuff may be people will get help from it.
I will explain as steps wise..
step1: For receiving mail to share point list you should have SMTP server install on your computer with its domain name properly configured
Step2: In Central Administration site in Operation section incoming mail settings needs to be done Here you will have to mention the name of domain server to which mail will be sent.
Step3: After done with all this the important factor is you will have to write the Email Receiver Handler library and register it to the specified share-point list. This event will fire whenever it receives mail and process as per the business logic you written in it.The DLL must need to add at GAC.
Step4: After registering the handler to list go to list settings.In communication tab there must be on link called In Coming Email settings. Click it and give the email address for this list.

Step5: Once done with above steps shoot a mail to specified library and check it out in C:\inetput\mailroot\drop folder . The mail comes first at here then Share point timer service is checking after one min duration for this folder.It transfer it to given list address.

Now I will give some code stuff for writing handler

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.EmailIntegration;
using System.Text.RegularExpressions;

namespace EmailReceiverHandlers
{
///
/// This class adds custom data from email to list
///

class MailEventHandler : SPEmailEventReceiver
{
SPListItem item;
public override void EmailReceived(SPList list, SPEmailMessage emailMessage, string receiverData)
{
try
{
list.ParentWeb.AllowUnsafeUpdates = true;
list.EnableAssignToEmail = true;
list.EnableAttachments = true;
item = list.Items.Add();
item["Title"] = emailMessage.Headers["subject"].ToString();
item.Update();
}
catch (Exception ex)
{
// EventLog.WriteEntry(sSource, "Error occured in EmailReceived method of class
MailEventHandler of type " + ex.Message, EventLogEntryType.Error);
}


}
}

Use OWSTIMER process from attach process for debugging the code.
Thanks..!

Wednesday, May 12, 2010

Error:Column name that you entered is already in use or reserved

Hi Friends
Few days back while working with list I got one problem I solved that after some goggling may be some you will help it out.
I want to create one custom column for my custom list but while creating it from list setings it was giving following error.











After some search I found that if you have created same column name with some list and if its added in site column gallery it goes there.If you delete that list all column names related with that list get deleted but it keep that column name reference in some hidden group which can not be seen through share point UI.

To solve this problem you have just execute the following script in address bar of that list page
as below
The Script is...
javascript:g_FieldName={};alert('Successfully cleared forbidden columns');













The above script clears all the values in the forbidden column collection array and gives you a confirmation. Now try creating the column now.You should be able to.