客户端发送电子邮件方法不起作用



我想使用SharePoint 2013客户端对象模型SendEmail方法发送电子邮件,但总是收到"必须指定收件人"错误。我在不同的电子邮件地址和几个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()

这里怎么了?

我认为电子邮件收件人必须解析为当前SharePoint网站用户。因此,您不能使用随机电子邮件地址作为电子邮件收件人。

尝试使用用户登录名而不是mailaddress;)

应该是:

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);

相关内容

  • 没有找到相关文章

最新更新