我想使用SharePoint 2013客户端对象模型SendEmail-Method发送电子邮件,但我总是得到“必须指定收件人”。错误。我尝试使用不同的电子邮件地址和多个SharePoint服务器,但在所有情况下都发生了错误。
示例源(C#):
string webUrl = "http://sharepoint.example.com/";
EmailProperties properties = new EmailProperties();
properties.To = new string[] { "email@example.com" };
properties.Subject = "Test subject";
properties.Body = "Test body";
ClientContext context = new ClientContext(webUrl);
Utility.SendEmail(context, properties);
context.ExecuteQuery(); // ServerException thrown here
context.Dispose();
错误讯息:
必须指定收件人。
错误类型:
System.InvalidOperationException
服务器堆栈跟踪:
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Microsoft.SharePoint.Utilities.SPUtility.SendEmail_Client(EmailProperties properties)
at Microsoft.SharePoint.ServerStub.Utilities.SPUtilityServerStub.InvokeStaticMethod(String methodName, XmlNodeList xmlargs, ProxyContext proxyContext, Boolean& isVoid)
at Microsoft.SharePoint.Client.ServerStub.InvokeStaticMethodWithMonitoredScope(String methodName, XmlNodeList args, ProxyContext proxyContext, Boolean& isVoid)
at Microsoft.SharePoint.Client.ClientMethodsProcessor.InvokeStaticMethod(String typeId, String methodName, XmlNodeList xmlargs, Boolean& isVoid)
at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessStaticMethod(XmlElement xe)
at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessOne(XmlElement xe)
at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessStatements(XmlNode xe)
at Microsoft.SharePoint.Client.ClientMethodsProcessor.Process()
这里有什么问题?
答案 0 :(得分:3)
我认为必须将电子邮件收件人解析为当前的SharePoint网站用户。因此,您不能将随机电子邮件地址用作电子邮件收件人
答案 1 :(得分:0)
尝试使用用户登录名而不是mailaddress;)
答案 2 :(得分:0)
应该是:
user.LoginName after EnusreUser for Ex:
User user = clientContext.Web.EnsureUser(strlogonName);
clientContext.Load(user);
clientContext.ExecuteQuery();
EmailProperties properties = new EmailProperties();
properties.To = new string[] { user.LoginName };
properties.Subject = "Test subject";
properties.Body = "Test body";
ClientContext context = new ClientContext(webUrl);
Utility.SendEmail(context, properties);