无法使用事件接收器在SharePoint中发送邮件
问题描述:
我有一个SharePoint 2010中的Web部件,它具有一个Event接收器,该接收器在项目添加到列表时触发。事件接收器应该发送一封邮件,但没有发送。无法使用事件接收器在SharePoint中发送邮件
当我尝试没有事件接收器时,它可以正常工作,我如何使用事件接收器发送邮件?
StringDictionary headers = new StringDictionary();
string body = "Hi!";
headers.Add("to", "[email protected]");
headers.Add("from", "[email protected]");
headers.Add("subject", "Paulo says hi");
headers.Add("content-type", "text/html");
SPUtility.SendEmail(web, headers, body)
谢谢你的帮助。
答
而事件接收器运行在HTTP请求的上下文中。据了解,SPUtility.SendEmail与此有关。通常的做法是在发送的电子邮件设置HttpContext.Current为null:
SPWeb thisWeb = thisSite.RootWeb;
string toField = "[email protected]";
string subject = "Test Message";
string body = "Message sent from SharePoint";
HttpContext oldContext = HttpContext.Current;
HttpContext.Current = null;
bool success = SPUtility.SendEmail(thisWeb, true, true, toField, subject, body);
HttpContext.Current = oldContext;
参考(向下滚动到评论):http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.sendemail(v=office.12).aspx
+0
谢谢,我试过了,但它没有解决问题。是否有关于事件接收器和在SharePoint中发送邮件的问题? – carruw 2012-04-20 08:52:44
您是否获得一个异常还是有可在SharePoint ULS错误日志? – 2012-04-20 12:29:00