我需要发送一封电子邮件,其中包含我的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);
}
我会很高兴你的答案!
答案 0 :(得分:0)
您可以按照以下方式获取:
foreach (SPListItem item in items) \\ items is your SPListItemCollection
{
var fieldValue = item["Field Name"].ToString();
}
答案 1 :(得分:0)
要将DateTime对象转换为CAML查询,请使用SPUtility.CreateISO8601DateTimeFromSystemDateTime()方法。
您需要的字段由i [“Title”]和i [“DueDate”]引用。
在foreach循环中使用StringBuilder对象构造邮件正文并在循环后发送电子邮件。您的代码将为每项任务发送一封邮件。