惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

博客园 - 疯子峰

oracle性能分析2 oracle性能分析 诡异的socket连接失败 ELK配置watcher 多进程 vs 多线程 关于时间 ELK日志平台 Java web项目 wordpress之客户端发布文章 神舟笔记本安装ubuntu 10.10 安装vs2010 AOP, Aspect-oriented programming 获取淘宝商品描述和价格 - 疯子峰 - 博客园 SPQuery查询语法简要说明(转) - 疯子峰 - 博客园 SPEmailEventReceiver 之导入附件EXCEL 安装Windows 2003更新后导致moss 无法访问 - 疯子峰 Ubuntu 的启动过程概览 linux 全局配置文件 vim 用户配置
为incoming mail绑定事件,SPEmailEventReceiver
疯子峰 · 2010-01-19 · via 博客园 - 疯子峰

 1) 新建 class 项目, 添加Microsoft.Sharepoint.dll引用。新建class并继承SPEmailEventReceiver

代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;namespace Sample{
    
public class Class1 : SPEmailEventReceiver
    {
        
public override void EmailReceived(SPList oList, SPEmailMessage oMessage,  string strReceiverData)   
        {  
            SPListItem oListItem 
= oList.Items.Add();  
            oListItem[
"Title"= oMessage.Headers["Subject"];  
            oListItem[
"Body"= oMessage.HtmlBody;  
            oListItem.Update();
foreach (SPEmailAttachment attachment in oMessage.Attachments)
            {
                
byte[] attachmentArray = new byte[attachment.ContentStream.Length];
                attachment.ContentStream.Read(attachmentArray, 
0, (int)attachment.ContentStream.Length);
                oList.RootFolder.Files.Add(attachment.FileName, attachmentArray);
            }
        }
    }
}

 2) 新建console项目,为列表绑定事件。

代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;namespace RegisterEvent
{
    
class Program
    {
        
static void Main(string[] args)
        {
            
string url = @"http://mossdev1/fa/corpsystem";
            SPSite curSite 
= new SPSite(url);
            SPWeb curWeb 
= curSite.OpenWeb();int t = 0;
            
foreach (SPList list in curWeb.Lists)
            {
                Console.WriteLine(t
++ + "" + list.Title);
            }
            SPList commentsList 
= curWeb.Lists["title value"];string asmName = "IISZ.SP.MailHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a3efae80b726e354";
            
string className = "IISZ.SP.MailHandler.Class1";for ( int i = 0 ; i <  commentsList.EventReceivers.Count ; i ++ )
            {
                Console.Write(commentsList.EventReceivers[i].Class.ToString());
                 commentsList.EventReceivers[i].Delete();
                 Console.WriteLine(
" -- deleted!");
            }
            commentsList.EventReceivers.Add(SPEventReceiverType.EmailReceived, asmName, className);
            
foreach (SPEventReceiverDefinition srd in commentsList.EventReceivers)
            {
                Console.WriteLine(srd.Class.ToString() 
+ " -- added!" );
            }

            Console.ReadLine();
        }
    }
}

3) 调试绑定的进程为owstimer.exe

4) 发送附件为txt的文本文件,报错。查看事件管理器为:

Error loading and running event receiver Sample.Class1 in Sample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a3efae80b726e354. Additional information is below.

: Value does not fall within the expected range.

5) 单步调试查到读取message.Attachments 报错,怀疑是文档库的问题,绑定事件到默认的文档库,同样错误。绑定到Announcements,OK.

6) 结论:document library 可以绑定邮件接收处理事件,但得不到附件信息。Announcements 一切可以。为什么?不知道。

浪费一整天,我是差不多先生。。。。

参考文档:

http://blogs.msdn.com/malag/archive/2009/05/13/attachments-disappear-with-custom-email-event-handler.aspx