0

我需要发送一封电子邮件,其中包含我的 caml 查询选择的行的列表项名称。我有这个代码:

                SPQuery filter = new SPQuery();
                filter.Query = string.Format("<Where><Leq><FieldRef Name=\"Revisionsdatum\" /><Value Type=\"DateTime\">{0}</Value></Leq></Where>", DateTime.Today.AddDays(14).ToString("yyyy-MM-ddThh:mm:ssZ"));
                SPListItemCollection items = yourList.GetItems(filter);
                foreach (var i in items)
                {
                    string from = string.Empty;
                    string smtpAddress = string.Empty;
                    string to = "Someone@someCompany.com";                    
                    string subject = "Dudate is coming";
                    string body = "<h1>Hello!</h1><p>In to weeks an importent dudates comes({0}) with the name {2}.";//Here I would like to ad the dudate and the ListItems Name but how?

                    // get a reference to the current site collection's content database 
                    SPWebApplication webApplication = this.Parent as SPWebApplication;
                    SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];

                    // get a reference to the "Tasks" list in the RootWeb of the first site collection in the content database 
                    SPWeb rootWeb = contentDb.Sites[0].RootWeb;

                    SPList listjob = rootWeb.Lists.TryGetList("Tasks");

                    // Get sender address from web application settings 
                    from = rootWeb.Site.WebApplication.OutboundMailSenderAddress;

                    // Get SMTP address from web application settings 
                    smtpAddress = rootWeb.Site.WebApplication.OutboundMailServiceInstance.Server.Address;

                    // Send an email if the news is approved 
                    bool emailSent = SendMail(smtpAddress, subject, body, true, from, to, null, null);


                }                

我会很高兴你的回答!

4

2 回答 2

0

您可以按以下方式获取它:

foreach (SPListItem item in items) \\ items is your SPListItemCollection 
{
    var fieldValue = item["Field Name"].ToString();
}
于 2014-02-06T12:03:59.527 回答
0

要将 DateTime 对象转换为 CAML 查询,请使用 SPUtility.CreateISO8601DateTimeFromSystemDateTime() 方法。

您需要的字段由 i["Title"] 和 i["DueDate"] 引用。

在 foreach 循环中使用 StringBuilder 对象来构造邮件正文并在循环后发送电子邮件。您的代码将为每个任务发送一封邮件。

于 2014-02-06T22:10:48.943 回答